public abstract class SearchQuery extends Object
Learn more
The example demonstrates a typical usage of the class.
String indexFolder = "c:\\MyIndex\\";
String documentsFolder = "c:\\MyDocuments\\";
Index index = new Index(indexFolder); // Creating index in the specified folder
index.add(documentsFolder); // Indexing documents from the specified folder
// Creating subquery of date range search
SearchQuery subquery1 = SearchQuery.createDateRangeQuery(new Date(2011, 6, 17), new Date(2013, 1, 1));
// Creating subquery of wildcard with number of missed words from 0 to 2
SearchQuery subquery2 = SearchQuery.createWildcardQuery(0, 2);
// Creating subquery of simple word
SearchQuery subquery3 = SearchQuery.createWordQuery("birth");
subquery3.setSearchOptions(new SearchOptions()); // Setting search options only for subquery 3
subquery3.getSearchOptions().getFuzzySearch().setEnabled(true);
subquery3.getSearchOptions().getFuzzySearch().setFuzzyAlgorithm(new TableDiscreteFunction(1));
// Combining subqueries into one query
SearchQuery query = SearchQuery.createPhraseSearchQuery(subquery1, subquery2, subquery3);
// Creating search options object with increased capacity of found occurrences
SearchOptions options = new SearchOptions(); // Overall search options
options.setMaxOccurrenceCountPerTerm(1000000);
options.setMaxTotalOccurrenceCount(10000000);
SearchResult result = index.search(query, options); // Searching
Modifier | Constructor and Description |
---|---|
protected |
SearchQuery() |
Modifier and Type | Method and Description |
---|---|
static SearchQuery |
createAndQuery(SearchQuery leftQuery,
SearchQuery rightQuery)
Creates a combined query that will find only documents which will be found for each original query.
|
static SearchQuery |
createDateRangeQuery(Date start,
Date end)
Creates a date range query.
|
static SearchQuery |
createFieldQuery(String fieldName,
SearchQuery query)
Adds a field to the specified query.
|
static SearchQuery |
createNotQuery(SearchQuery query)
Creates an inverted query that will find the rest documents in an index against ones which will be found for the original query.
|
static SearchQuery |
createNumericRangeQuery(long start,
long end)
Creates a numeric range query.
|
static SearchQuery |
createOrQuery(SearchQuery leftQuery,
SearchQuery rightQuery)
Creates a combined query that will find all the documents which will be found at least for one of the original queries.
|
static SearchQuery |
createPhraseSearchQuery(SearchQuery... queries)
Creates a phrase search query.
|
static SearchQuery |
createRegexQuery(String pattern)
Creates a regular expression query.
|
static SearchQuery |
createRegexQuery(String pattern,
int options)
Creates a regular expression query.
|
static SearchQuery |
createWildcardQuery(int count)
Creates a wildcard for the phrase search.
|
static SearchQuery |
createWildcardQuery(int minCount,
int maxCount)
Creates a wildcard for the phrase search.
|
static SearchQuery |
createWordPatternQuery(WordPattern pattern)
Creates a word pattern query.
|
static SearchQuery |
createWordQuery(String term)
Creates a simple word query.
|
protected static SearchQuery |
deserialize(byte[] array) |
abstract SearchQuery |
getChild(int index)
Gets a child query by an index.
|
int |
getChildCount()
Gets the number of child queries.
|
String |
getFieldName()
Gets the field name.
|
SearchQuery |
getFirstChild()
Gets the first child query.
|
SearchOptions |
getSearchOptions()
Gets the search options of this seach query.
|
SearchQuery |
getSecondChild()
Gets the second child query.
|
protected static byte[] |
serialize(SearchQuery searchQuery) |
void |
setSearchOptions(SearchOptions value)
Sets the search options of this seach query.
|
abstract String |
toString()
Returns a String that represents the current
SearchQuery instance. |
public String getFieldName()
Gets the field name.
public int getChildCount()
Gets the number of child queries.
public SearchQuery getFirstChild()
Gets the first child query.
public SearchQuery getSecondChild()
Gets the second child query.
public abstract SearchQuery getChild(int index)
Gets a child query by an index.
index
- The index.public final SearchOptions getSearchOptions()
Gets the search options of this seach query.
public final void setSearchOptions(SearchOptions value)
Sets the search options of this seach query.
value
- The search options.public abstract String toString()
Returns a String that represents the current SearchQuery
instance.
public static SearchQuery createWordQuery(String term)
Creates a simple word query.
term
- The term to search for.public static SearchQuery createWordPatternQuery(WordPattern pattern)
Creates a word pattern query.
pattern
- The word pattern.public static SearchQuery createRegexQuery(String pattern)
Creates a regular expression query.
pattern
- The regular expression pattern to match.public static SearchQuery createRegexQuery(String pattern, int options)
Creates a regular expression query.
pattern
- The regular expression pattern to match.options
- A bitwise combination of the enumeration values that modify the regular expression.
This value must contain RegexOptions.IgnoreCase
flag.public static SearchQuery createNumericRangeQuery(long start, long end)
Creates a numeric range query.
start
- The start value of a range.end
- The end value of a range.public static SearchQuery createDateRangeQuery(Date start, Date end)
Creates a date range query.
start
- The start value of a range.end
- The end value of a range.public static SearchQuery createPhraseSearchQuery(SearchQuery... queries)
Creates a phrase search query.
queries
- The child queries.public static SearchQuery createFieldQuery(String fieldName, SearchQuery query)
Adds a field to the specified query.
fieldName
- The field name to search in.query
- The query to add the field.public static SearchQuery createNotQuery(SearchQuery query)
Creates an inverted query that will find the rest documents in an index against ones which will be found for the original query.
query
- The query to invert.public static SearchQuery createAndQuery(SearchQuery leftQuery, SearchQuery rightQuery)
Creates a combined query that will find only documents which will be found for each original query.
leftQuery
- The left child query.rightQuery
- The right child query.public static SearchQuery createOrQuery(SearchQuery leftQuery, SearchQuery rightQuery)
Creates a combined query that will find all the documents which will be found at least for one of the original queries.
leftQuery
- The left child query.rightQuery
- The right child query.public static SearchQuery createWildcardQuery(int count)
Creates a wildcard for the phrase search.
count
- The number of words in the wildcard.public static SearchQuery createWildcardQuery(int minCount, int maxCount)
Creates a wildcard for the phrase search.
minCount
- The minimum number of words in the wildcard.maxCount
- The maximum number of words in the wildcard.protected static SearchQuery deserialize(byte[] array)
protected static byte[] serialize(SearchQuery searchQuery)