SearchQuery

Inheritance: java.lang.Object

public abstract class SearchQuery

Represents a search query in object form.

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
 

Methods

Method Description
getFieldName() Gets the field name.
getChildCount() Gets the number of child queries.
getFirstChild() Gets the first child query.
getSecondChild() Gets the second child query.
getChild(int index) Gets a child query by an index.
getSearchOptions() Gets or sets the search options of this seach query.
setSearchOptions(SearchOptions value) Gets or sets the search options of this seach query.
toString() Returns a System.String that represents the current SearchQuery instance.
createWordQuery(String term) Creates a simple word query.
createWordPatternQuery(WordPattern pattern) Creates a word pattern query.
createRegexQuery(String pattern) Creates a regular expression query.
createRegexQuery(String pattern, int options) Creates a regular expression query.
createNumericRangeQuery(long start, long end) Creates a numeric range query.
createDateRangeQuery(Date start, Date end) Creates a date range query.
createPhraseSearchQuery(SearchQuery[] queries) Creates a phrase search query.
createFieldQuery(String fieldName, SearchQuery query) Adds a field to the specified query.
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.
createAndQuery(SearchQuery leftQuery, SearchQuery rightQuery) Creates a combined query that will find only documents which will be found for each original query.
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.
createWildcardQuery(int count) Creates a wildcard for the phrase search.
createWildcardQuery(int minCount, int maxCount) Creates a wildcard for the phrase search.

getFieldName()

public String getFieldName()

Gets the field name.

Returns: java.lang.String - The field name.

getChildCount()

public int getChildCount()

Gets the number of child queries.

Returns: int - The number of child queries.

getFirstChild()

public SearchQuery getFirstChild()

Gets the first child query.

Returns: SearchQuery - The first child query.

getSecondChild()

public SearchQuery getSecondChild()

Gets the second child query.

Returns: SearchQuery - The second child query.

getChild(int index)

public abstract SearchQuery getChild(int index)

Gets a child query by an index.

Parameters:

Parameter Type Description
index int The index.

Returns: SearchQuery - A child query corresponding the specified index.

getSearchOptions()

public final SearchOptions getSearchOptions()

Gets or sets the search options of this seach query.

Returns: SearchOptions - The search options.

setSearchOptions(SearchOptions value)

public final void setSearchOptions(SearchOptions value)

Gets or sets the search options of this seach query.

Parameters:

Parameter Type Description
value SearchOptions The search options.

toString()

public abstract String toString()

Returns a System.String that represents the current SearchQuery instance.

Returns: java.lang.String - A System.String that represents the current SearchQuery instance.

createWordQuery(String term)

public static SearchQuery createWordQuery(String term)

Creates a simple word query.

Parameters:

Parameter Type Description
term java.lang.String The term to search for.

Returns: SearchQuery - A simple word query.

createWordPatternQuery(WordPattern pattern)

public static SearchQuery createWordPatternQuery(WordPattern pattern)

Creates a word pattern query.

Parameters:

Parameter Type Description
pattern WordPattern The word pattern.

Returns: SearchQuery - A word pattern query.

createRegexQuery(String pattern)

public static SearchQuery createRegexQuery(String pattern)

Creates a regular expression query.

Parameters:

Parameter Type Description
pattern java.lang.String The regular expression pattern to match.

Returns: SearchQuery - A regular expression query.

createRegexQuery(String pattern, int options)

public static SearchQuery createRegexQuery(String pattern, int options)

Creates a regular expression query.

Parameters:

Parameter Type Description
pattern java.lang.String The regular expression pattern to match.
options int A bitwise combination of the enumeration values that modify the regular expression. This value must contain RegexOptions.IgnoreCase flag.

Returns: SearchQuery - A regular expression query.

createNumericRangeQuery(long start, long end)

public static SearchQuery createNumericRangeQuery(long start, long end)

Creates a numeric range query.

Parameters:

Parameter Type Description
start long The start value of a range.
end long The end value of a range.

Returns: SearchQuery - A numeric range query.

createDateRangeQuery(Date start, Date end)

public static SearchQuery createDateRangeQuery(Date start, Date end)

Creates a date range query.

Parameters:

Parameter Type Description
start java.util.Date The start value of a range.
end java.util.Date The end value of a range.

Returns: SearchQuery - A date range query.

createPhraseSearchQuery(SearchQuery[] queries)

public static SearchQuery createPhraseSearchQuery(SearchQuery[] queries)

Creates a phrase search query.

Parameters:

Parameter Type Description
queries SearchQuery[] The child queries.

Returns: SearchQuery - A phrase search query.

createFieldQuery(String fieldName, SearchQuery query)

public static SearchQuery createFieldQuery(String fieldName, SearchQuery query)

Adds a field to the specified query.

Parameters:

Parameter Type Description
fieldName java.lang.String The field name to search in.
query SearchQuery The query to add the field.

Returns: SearchQuery - A query with the field to search in.

createNotQuery(SearchQuery query)

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.

Parameters:

Parameter Type Description
query SearchQuery The query to invert.

Returns: SearchQuery - A combined NOT query.

createAndQuery(SearchQuery leftQuery, SearchQuery rightQuery)

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.

Parameters:

Parameter Type Description
leftQuery SearchQuery The left child query.
rightQuery SearchQuery The right child query.

Returns: SearchQuery - A combined AND query.

createOrQuery(SearchQuery leftQuery, SearchQuery rightQuery)

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.

Parameters:

Parameter Type Description
leftQuery SearchQuery The left child query.
rightQuery SearchQuery The right child query.

Returns: SearchQuery - A combined OR query.

createWildcardQuery(int count)

public static SearchQuery createWildcardQuery(int count)

Creates a wildcard for the phrase search.

Parameters:

Parameter Type Description
count int The number of words in the wildcard.

Returns: SearchQuery - A wildcard for the phrase search.

createWildcardQuery(int minCount, int maxCount)

public static SearchQuery createWildcardQuery(int minCount, int maxCount)

Creates a wildcard for the phrase search.

Parameters:

Parameter Type Description
minCount int The minimum number of words in the wildcard.
maxCount int The maximum number of words in the wildcard.

Returns: SearchQuery - A wildcard for the phrase search.