@Experimental public interface LuceneService
LuceneIndex
and create the LuceneQuery
via
LuceneQueryFactory
Example:
At client and server JVM, initializing cache will create the LuceneServiceImpl object,
which is a singleton at each JVM.
At each server JVM, for data region to create index, create the index on fields with default analyzer:
LuceneIndex index = luceneService.createIndex(indexName, regionName, "field1", "field2", "field3");
or create index on fields with specified analyzer:
LuceneIndex index = luceneService.createIndex(indexName, regionName, analyzerPerField);
We can also create index via cache.xml or gfsh.
At client side, create query and run the search:
LuceneQuery query = luceneService.createLuceneQueryFactory().setLimit(200).setPageSize(20)
.setResultTypes(SCORE, VALUE, KEY).setFieldProjection("field1", "field2")
.create(indexName, regionName, querystring, analyzer);
The querystring is using lucene's queryparser syntax, such as "field1:zhou* AND field2:[email protected]"
PageableLuceneQueryResults results = query.search();
If pagination is not specified:
List list = results.getNextPage(); // return all results in one getNextPage() call
or if paging is specified:
if (results.hasNextPage()) {
List page = results.nextPage(); // return resules page by page
}
The item of the list is either the domain object or instance of LuceneResultStruct
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
REGION_VALUE_FIELD
A special field name that indicates that the entire region value should be indexed.
|
Modifier and Type | Method and Description |
---|---|
void |
createIndex(java.lang.String indexName,
java.lang.String regionPath,
java.util.Map<java.lang.String,org.apache.lucene.analysis.Analyzer> analyzerPerField)
Create a lucene index using specified analyzer per field
|
void |
createIndex(java.lang.String indexName,
java.lang.String regionPath,
java.lang.String... fields)
Create a lucene index using default analyzer.
|
LuceneQueryFactory |
createLuceneQueryFactory()
create LuceneQueryFactory
|
void |
destroyIndex(LuceneIndex index)
Deprecated.
TODO This feature is not yet implemented
|
java.util.Collection<LuceneIndex> |
getAllIndexes()
get all the lucene indexes.
|
LuceneIndex |
getIndex(java.lang.String indexName,
java.lang.String regionPath)
Get the lucene index object specified by region name and index name
|
static final java.lang.String REGION_VALUE_FIELD
void createIndex(java.lang.String indexName, java.lang.String regionPath, java.lang.String... fields)
fields
- The fields of the object to index. Only fields listed here will be stored in the
index. Fields should map to PDX fieldNames if the object is serialized with PDX, or to
java fields on the object otherwise. The special field name
{REGION_VALUE_FIELD
} indicates that the entire value should be stored as a
single field in the index.void createIndex(java.lang.String indexName, java.lang.String regionPath, java.util.Map<java.lang.String,org.apache.lucene.analysis.Analyzer> analyzerPerField)
indexName
- index nameregionPath
- region nameanalyzerPerField
- A map of fields to analyzers. See
{createIndex(String, String, String...)
} for details on valid values for
fields. Each field will be tokenized using the provided Analyzer.@Deprecated void destroyIndex(LuceneIndex index)
index
- index objectLuceneIndex getIndex(java.lang.String indexName, java.lang.String regionPath)
indexName
- index nameregionPath
- region namejava.util.Collection<LuceneIndex> getAllIndexes()
LuceneQueryFactory createLuceneQueryFactory()