public interface LuceneService
To obtain an instance of LuceneService, use
LuceneServiceProvider.get(GemFireCache cache)
.
Lucene indexes can be created using gfsh, xml, or the java API. Below is an example of creating a Lucene index with the java API. The Lucene index should be created on each member that has the region that is being indexed.
{ @code luceneService.createIndexFactory() .addField("name") .addField("zipcode") .addField("email", new KeywordAnalyzer()) .create(indexName, regionName); }
You can also specify what Analyzer
to use for each field. In the example above, email is
being tokenized with the KeywordAnalyzer so it is treated as a single word. The default analyzer
if none is specified is the StandardAnalyzer
.
Indexes should be created on all peers that host the region being indexed. Clients do not need to define the index, they can directly execute queries using this service.
Queries on this service can return either the region keys, values, or both that match a Lucene
query expression. To execute a query, start with the createLuceneQueryFactory()
method.
{ @code LuceneQuery query = luceneService.createLuceneQueryFactory().setLimit(200).create(indexName, regionName, "name:John AND zipcode:97006", defaultField); Collection results = query.findValues(); }
The Lucene index data is colocated with the region that is indexed. This means that the index data will be partitioned, copied, or persisted using the same configuration options you provide for the region that is indexed. Queries will automatically be distributed in parallel to cover all partitions of a partitioned region.
Indexes are maintained asynchronously, so changes to regions may not be immediately reflected in
the index. This means that queries executed using this service may return stale results. Use the
waitUntilFlushed(String, String, long, TimeUnit)
method if you need to wait for your
changes to be indexed before executing a query, however this method should be used sparingly
because it is an expensive operation.
Currently, only partitioned regions are supported. Creating an index on a region with
DataPolicy.REPLICATE
will fail.
Modifier and Type | Field and Description |
---|---|
static String |
REGION_VALUE_FIELD
A special field name that indicates that the entire region value should be indexed.
|
Modifier and Type | Method and Description |
---|---|
LuceneIndexFactory |
createIndexFactory()
Get a factory for creating a Lucene index on this member.
|
LuceneQueryFactory |
createLuceneQueryFactory()
Create a factory for building a Lucene query.
|
void |
destroyIndex(String indexName,
String regionPath)
Destroy the Lucene index
|
void |
destroyIndexes(String regionPath)
Destroy all the Lucene indexes for the region
|
Collection<LuceneIndex> |
getAllIndexes()
get all the Lucene indexes.
|
Cache |
getCache()
returns the cache to which the LuceneService belongs
|
LuceneIndex |
getIndex(String indexName,
String regionPath)
Get the Lucene index object specified by region name and index name
|
boolean |
isIndexingInProgress(String indexName,
String regionPath)
Returns if the indexing process is in progress
Before executing a lucene query, it can be checked if the indexing operation is in progress.
|
boolean |
waitUntilFlushed(String indexName,
String regionPath,
long timeout,
TimeUnit unit)
Wait until the current entries in cache are indexed.
|
static final String REGION_VALUE_FIELD
LuceneIndexFactory createIndexFactory()
void destroyIndex(String indexName, String regionPath)
indexName
- the name of the index to destroyregionPath
- the path of the region whose index to destroyvoid destroyIndexes(String regionPath)
regionPath
- The path of the region on which to destroy the indexesLuceneIndex getIndex(String indexName, String regionPath)
indexName
- index nameregionPath
- region nameCollection<LuceneIndex> getAllIndexes()
LuceneQueryFactory createLuceneQueryFactory()
Cache getCache()
boolean waitUntilFlushed(String indexName, String regionPath, long timeout, TimeUnit unit) throws InterruptedException
indexName
- index nameregionPath
- region nametimeout
- max wait timeunit
- Time unit associated with the max wait timeInterruptedException
- if the thread is interruptedboolean isIndexingInProgress(String indexName, String regionPath)
LuceneIndexCreationInProgressException
indexName
- index nameregionPath
- region name