THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
LuceneQueryFactory
Code Block |
---|
public enum/** ResultType { * Set page /** size for a query result. *The default Querypage resultssize onlyis contain0 value, which ismeans theno default settingpagination. * If fieldspecified projectionnegative is specifiedvalue, usethrow projectedIllegalArgumentException fields' values instead* of whole domain object@param pageSize * @return */itself VALUE,*/ LuceneQueryFactory setPageSize(int pageSize); /** * Set * Query results contain scoremax limit of result for a query * If specified */ limit is less or SCORE, equal to zero, throw IllegalArgumentException /** @param limit * Query results contain key@return itself */ LuceneQueryFactory KEYsetResultLimit(int limit); }; /** * Set pagea sizelist forof afields queryfor result. The default page size is 0 which means no pagination projection. * If specified negative value, throw IllegalArgumentException * @param pageSizefieldNames * @return itself */ LuceneQueryFactory setPageSize(int pageSizesetProjectionFields(String... fieldNames); /** * SetCreate maxwrapper limitobject of result for a querylucene's QueryParser object using default standard analyzer. * The IfqueryString specifiedis limitusing islucene less or equal to zero, throw IllegalArgumentExceptionQueryParser's syntax. QueryParser is for easy-to-use * @param limitwith human understandable syntax. * @return itself */ @param LuceneQueryFactoryregionName setResultLimit(int limit);region name /*** @param indexName index name * set@param weatherqueryString toquery includestring SCORE,in KEYlucene inQueryParser's resultsyntax * @param K the key type in the query results * @param resultTypesV the value type in the query results * @return LuceneQuery itselfobject */ @throws ParseException LuceneQueryFactory setResultTypes(ResultType... resultTypes); /** * Set a list of fields for result projection. * * @param fieldNames */ public <K, V> LuceneQuery<K, V> create(String indexName, String regionName, String queryString) throws ParseException; /** * @returnCreates itself a wrapper object */ LuceneQueryFactory setProjectionFields(String... fieldNames); /**for Lucene's Query object. This {@link LuceneQuery} builder method could be used in * Create wrapper object for lucene advanced cases, such as cases where Lucene's QueryParserQuery object. construction needs *Lucene's TheAPI queryStringover isquery usingstring. luceneThe QueryParser's syntax. QueryParser is for easy-to-use * with human understandable syntax. * {@link QueryDeserializer} will be used to re-construct the Lucene Query object on remote hosts. * * @param regionNameindexName regionindex name * @param indexNameregionName indexregion name * @param provider queryStringconstructs queryand stringprovides ina luceneLucene QueryParser'sQuery syntaxobject * @param analyzerK lucenethe Analyzerkey totype parsein the queryStringquery results * @return LuceneQuery object@param V the value type in the query results * @return @throwsLuceneQuery ParseExceptionobject */ public LuceneQuery <K, V> LuceneQuery<K, V> create(String indexName, String regionName, String queryString, Analyzer analyzer) throws ParseException; LuceneQueryProvider provider); /** * The *instances Createof wrapperthis objectclass forwill lucene'sbe QueryParserused objectfor usingdistributing defaultLucene standardQuery analyzer. objects and re-constructing *the TheQuery queryStringobject. is* usingIf lucenenecessary QueryParser's syntax. QueryParser is for easy-to-use * with human understandable syntax. * * @param regionName region name * @param indexName index name * @param queryString query string in lucene QueryParser's syntax * @return LuceneQuery object * @throws ParseException */ public LuceneQuery create(String indexName, String regionName, String queryString) throws ParseException; the implementation needs to take care of serializing and de-serializing Lucene Query object. Geode * respects the DataSerializable contract to provide optimal object serialization. For instance, * {@link LuceneQueryProvider}'s toData method will be used to serialize it when it is sent to another member of the * distributed system. Implementation of DataSerializable can provide a zero-argument constructor that will be invoked * when they are read with DataSerializer.readObject. */ public interface LuceneQueryProvider extends Serializable { /** * Create@return wrapperA object for lucene's Lucene Query object. which could *be Advancedused lucenefor usersexecuting canLucene customizedSearch theiron own Query object and directly use in this API. indexed data * * @param regionNameThe regionlocal name lucene index the *query @paramis indexNamebeing indexconstructed nameagainst. * @param@throws queryQueryException luceneif Querythe object provider fails to *construct @returnthe LuceneQueryquery object */ public LuceneQueryQuery creategetQuery(StringLuceneIndex indexName,index) String regionName, Query query);throws QueryException; } |
LuceneQuery
Code Block |
---|
/**
* Provides wrapper object of Lucene's Query object and execute the search.
* <p>Instances of this interface are created using
* {@link LuceneQueryFactory#create}.
*
*/
public interface LuceneQuery {
/**
* Execute the search and get results.
*/
public LuceneQueryResults<?> search();
/**
* Get page size setting of current query.
*/
public int getPageSize();
/**
* Get limit size setting of current query.
*/
public int getLimit();
/**
* Get result types setting of current query.
*/
public ResultType[] getResultTypes();
/**
* Get projected fields setting of current query.
*/
public String[] getProjectedFieldNames();
} |
LuceneResultStruct
Code Block |
---|
/** * Return the value associated with the given field name * * @param fieldName the String name of the field * @return the value associated with the specified field * @throws IllegalArgumentException If this struct does not have a field named fieldName */ public Object getProjectedField(String fieldName); /** * Return key of the entry * * @return key * @throws IllegalArgumentException If this struct does not contain key */ public Object getKey(); /** * Return value of the entry * * @return value the whole domain object * @throws IllegalArgumentException If this struct does not contain value */ public Object getValue(); /** * Return score of the query * * @return score * @throws IllegalArgumentException If this struct does not contain score */ public Double getScore(); /** * Get the types of values ordered list * Item values in thesame listorder couldas be either ResultType, or field nameresult types * @return the array of result typesvalues */ public Object[] getNamesgetResultValues(); } |
Examples
Code Block |
---|
// Get LuceneService LuceneService luceneService /** * Get the values in same order as result types * @return the array of values */ public Object[] getResultValues(); } |
Examples
Code Block |
---|
// Get LuceneService LuceneService luceneService = LuceneServiceProvider.get(cache); // Create Index on fields with default analyzer: LuceneIndex index = luceneService.createIndex(indexName, regionName, = LuceneServiceProvider.get(cache); // Create Index on fields with default analyzer: LuceneIndex index = luceneService.createIndex(indexName, regionName, "field1", "field2", "field3"); // create index on fields with specified analyzer: LuceneIndex index = luceneService.createIndex(indexName, regionName, analyzerPerField); // Create Query LuceneQuery query = luceneService.createLuceneQueryFactory().setLimit(200).setPageSize(20) .setResultType(SCORE, VALUE, KEY).setFieldProjection("field1", "field2", "field3"); // create index on fields with specified analyzer: LuceneIndex index = luceneService.createIndex.create(indexName, regionName, analyzerPerFieldquerystring, analyzer); // Search Createusing Query LuceneQueryLuceneQueryResults queryresults = luceneServicequery.createLuceneQueryFactorysearch().setLimit(200).setPageSize(20) .setResultType(SCORE, VALUE, KEY).setFieldProjection("field1", "field2") .create(indexName, regionName, querystring, analyzer); // Search using Query LuceneQueryResults results = query.search(); List values = results.getNextPage(); ; List values = results.getNextPage(); // return all results in one page // Pagination while (results.hasNextPage()) List page = results.getNextPage(); // return result page by page for (LuceneResultStruct r : page) { System.out.prinlnt(r.getValue()); } } |
Gfsh API
Code Block |
---|
// Create Index gfsh> create lucene- index --name=indexName --region=/orders --fields=customer,tags // Destory Index gfsh> destroy lucene- index --name=indexName --region=/orders Execute Lucene query gfsh> luceneQuery --regionName=/orders -queryStrings="" --limit=100 page-size=10 |
XML Configuration
=indexName --region=/orders
Execute Lucene query
gfsh> lucene query --regionName=/orders -queryStrings="" --limit=100 page-size=10 |
XML Configuration
Code Block |
---|
<cache
xmlns="http://schema.pivotal.io/gemfire/cache"
xmlns:lucene="http://geode.incubator.apache.org/schema/lucene"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schema.pivotal.io/gemfire/cache
http://schema.pivotal.io/gemfire/cache/cache-9.0.xsd
http://geode.incubator.apache.org/schema/lucene
http://geode.incubator.apache.org/schema/lucene/lucene-1.0.xsd"
version="9.0">
|
Code Block |
---|
<region name="region"> <lucene-:index indexNamename="luceneIndex"> <FieldDefinition<lucene:field name="fieldName" analyzer="KeywordAnalyzer"/> </lucene-:index> </region> |
REST API
TBD - But using solr to provide a REST API might make a lot of sense
Spring Data GemFire Support
TBD - But the Searchable annotation described in this blog might be a good place to start.
Implementation Flowchart
...