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 and Type | Method and Description |
|---|---|
static SearchQuery |
createAndQuery(SearchQuery[] queries)
Creates a combined query that will find only documents which will be found for each original query.
|
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[] queries)
Creates a combined query that will find all the documents which will be found at least for one of the original queries.
|
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.
|
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 or sets the search options of this seach query.
|
SearchQuery |
getSecondChild()
Gets the second child query.
|
void |
setSearchOptions(SearchOptions value)
Gets or sets the search options of this seach query.
|
abstract String |
toString()
Returns a
System.String that represents the current SearchQuery instance. |
public static SearchQuery createAndQuery(SearchQuery[] queries)
queries - The field name to search in.public static SearchQuery createAndQuery(SearchQuery leftQuery, SearchQuery rightQuery)
leftQuery - The left child query.rightQuery - The right child query.public static SearchQuery createDateRangeQuery(Date start, Date end)
start - The start value of a range.end - The end value of a range.public static SearchQuery createFieldQuery(String fieldName, SearchQuery query)
fieldName - The field name to search in.query - The query to add the field.public static SearchQuery createNotQuery(SearchQuery query)
query - The query to invert.public static SearchQuery createNumericRangeQuery(long start, long end)
start - The start value of a range.end - The end value of a range.public static SearchQuery createOrQuery(SearchQuery[] queries)
queries - The child queries.public static SearchQuery createOrQuery(SearchQuery leftQuery, SearchQuery rightQuery)
leftQuery - The left child query.rightQuery - The right child query.public static SearchQuery createPhraseSearchQuery(SearchQuery... queries)
queries - The child queries.public static SearchQuery createRegexQuery(String pattern)
pattern - The regular expression pattern to match.public static SearchQuery createRegexQuery(String pattern, int options)
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 createWildcardQuery(int count)
count - The number of words in the wildcard.public static SearchQuery createWildcardQuery(int minCount, int maxCount)
minCount - The minimum number of words in the wildcard.maxCount - The maximum number of words in the wildcard.public static SearchQuery createWordPatternQuery(WordPattern pattern)
pattern - The word pattern.public static SearchQuery createWordQuery(String term)
term - The term to search for.public abstract SearchQuery getChild(int index)
index - The index.public int getChildCount()
public String getFieldName()
public SearchQuery getFirstChild()
public final SearchOptions getSearchOptions()
public SearchQuery getSecondChild()
public final void setSearchOptions(SearchOptions value)
value - The search options.Copyright © 2026. All rights reserved.