public abstract class LuceneQuery<T> extends SearchQuery<T>
Modifier and Type | Class and Description |
---|---|
static class |
LuceneQuery.MatchType
Normal uses a textual match algorithm for the search
Soundex indicates to use a Phonetic search strategy
|
Constructor and Description |
---|
LuceneQuery(Class<T> type,
org.hibernate.Session session) |
Modifier and Type | Method and Description |
---|---|
protected void |
adjustFullTextQuery(org.hibernate.search.FullTextQuery fullTextQuery)
It is called by the constructor after creating
FullTextQuery . |
static String |
escapeQuery(String query)
Escape any characters that can be interpreted by the query parser.
|
LuceneQuery<T> |
exclude(String field,
Object value)
Exclude any items with the given value in the specified field.
|
LuceneQuery<T> |
exclude(String field,
Object[] values)
Exclude any items with the given values in the specified field.
|
protected org.hibernate.search.FullTextSession |
getFullTextSession()
Gives you access to the full text session.
|
LuceneQuery<T> |
include(String field,
Collection<?> values) |
LuceneQuery<T> |
include(String field,
Object value)
Include items with the given value in the specified field.
|
LuceneQuery<T> |
include(String field,
Object[] values)
Include items with any of the given values in the specified field.
|
List<T> |
list()
Runs the query returning a list with all results.
|
ListPart<T> |
listPart(Long firstResult,
Long maxResults)
Runs the query returning a partial results list.
|
ListPart<Object[]> |
listPartProjection(Integer firstResult,
Integer maxResults,
String... fields) |
ListPart<Object[]> |
listPartProjection(Long firstResult,
Long maxResults,
String... fields) |
List<Object[]> |
listProjection(String... fields) |
protected org.apache.lucene.queryparser.classic.MultiFieldQueryParser |
newMultipleFieldQueryParser(Collection<String> fields,
LuceneQuery.MatchType matchType) |
static <T> LuceneQuery<T> |
newQuery(Class<T> type,
org.hibernate.Session session,
String query)
The preferred way to create a Lucene query using the query parser.
|
static <T> LuceneQuery<T> |
newQuery(Class<T> type,
org.hibernate.Session session,
String query,
Collection<String> fields) |
static <T> LuceneQuery<T> |
newQuery(Class<T> type,
org.hibernate.Session session,
String query,
Collection<String> fields,
LuceneQuery.MatchType matchType) |
protected org.hibernate.search.query.dsl.QueryBuilder |
newQueryBuilder()
You can use it in
prepareQuery() . |
protected org.apache.lucene.queryparser.classic.QueryParser |
newQueryParser()
You can use it in
prepareQuery() . |
protected abstract org.apache.lucene.search.Query |
prepareQuery()
It is called by the constructor to get an instance of a query.
|
long |
resultSize() |
LuceneQuery<T> |
skipSame(String field)
Skip elements, values of which repeat in the given field.
|
LuceneQuery<T> |
skipSame(String field,
LuceneQuery<?> luceneQuery)
Skip elements, values of which repeat in the given field.
|
T |
uniqueResult()
Runs the query returning a unique result.
|
LuceneQuery<T> |
useOrQueryParser() |
getSession, getType, listPart
public static <T> LuceneQuery<T> newQuery(Class<T> type, org.hibernate.Session session, String query, Collection<String> fields)
public static <T> LuceneQuery<T> newQuery(Class<T> type, org.hibernate.Session session, String query, Collection<String> fields, LuceneQuery.MatchType matchType)
public static <T> LuceneQuery<T> newQuery(Class<T> type, org.hibernate.Session session, String query)
type
- filters on typesession
- query
- public static String escapeQuery(String query)
query
- public LuceneQuery<T> useOrQueryParser()
public LuceneQuery<T> include(String field, Object value)
It is a filter applied before the query.
field
- value
- public LuceneQuery<T> include(String field, Collection<?> values)
public LuceneQuery<T> include(String field, Object[] values)
It is a filter applied before the query.
field
- values
- public LuceneQuery<T> exclude(String field, Object value)
It is a filter applied before the query.
field
- value
- public LuceneQuery<T> exclude(String field, Object[] values)
It is a filter applied before the query.
field
- values
- protected abstract org.apache.lucene.search.Query prepareQuery() throws org.apache.lucene.queryparser.classic.ParseException
To construct the query you can use newQueryBuilder()
or newQueryParser()
,
which are created for the proper type.
org.apache.lucene.queryparser.classic.ParseException
protected void adjustFullTextQuery(org.hibernate.search.FullTextQuery fullTextQuery)
FullTextQuery
.
You can override it to adjust the full text query, e.g. add a filter.
fullTextQuery
- protected org.hibernate.search.query.dsl.QueryBuilder newQueryBuilder()
prepareQuery()
.protected org.apache.lucene.queryparser.classic.QueryParser newQueryParser()
prepareQuery()
.protected org.apache.lucene.queryparser.classic.MultiFieldQueryParser newMultipleFieldQueryParser(Collection<String> fields, LuceneQuery.MatchType matchType)
protected org.hibernate.search.FullTextSession getFullTextSession()
public LuceneQuery<T> skipSame(String field)
Only first elements will be included in the results.
Note: This method must be called as last when constructing a query. When called it will project the query and create a filter to eliminate duplicates.
field
- public LuceneQuery<T> skipSame(String field, LuceneQuery<?> luceneQuery)
Only first elements will be included in the results.
Note: This method must be called as last when constructing a query. When called it will project the query and create a filter to eliminate duplicates.
field
- luceneQuery
- results of which should be skipped too. It works only for queries, which called skipSame as well.public T uniqueResult()
SearchQuery
uniqueResult
in class SearchQuery<T>
public List<T> list()
SearchQuery
list
in class SearchQuery<T>
public ListPart<T> listPart(Long firstResult, Long maxResults)
SearchQuery
listPart
in class SearchQuery<T>
firstResult
- position of the first result to return, optionalmaxResults
- maximum number of results, optionalpublic long resultSize()
resultSize
in class SearchQuery<T>
SearchQuery.resultSize()
public ListPart<Object[]> listPartProjection(Long firstResult, Long maxResults, String... fields)
Copyright © 2024 OpenMRS Inc.. All rights reserved.