SearchQuery

SearchQuery class

Represents a search query in object form.

public abstract class SearchQuery

Properties

Name Description
virtual ChildCount { get; } Gets the number of child queries.
virtual FieldName { get; } Gets the field name.
virtual FirstChild { get; } Gets the first child query.
SearchOptions { get; set; } Gets or sets the search options of this seach query.
virtual SecondChild { get; } Gets the second child query.

Methods

Name Description
static CreateAndQuery(params SearchQuery[]) Creates a combined query that will find only documents which will be found for each original query.
static CreateAndQuery(SearchQuery, SearchQuery) Creates a combined query that will find only documents which will be found for each original query.
static CreateDateRangeQuery(DateTime, DateTime) Creates a date range query.
static CreateFieldQuery(string, SearchQuery) Adds a field to the specified query.
static CreateNotQuery(SearchQuery) Creates an inverted query that will find the rest documents in an index against ones which will be found for the original query.
static CreateNumericRangeQuery(long, long) Creates a numeric range query.
static CreateOrQuery(params SearchQuery[]) Creates a combined query that will find all the documents which will be found at least for one of the original queries.
static CreateOrQuery(SearchQuery, SearchQuery) Creates a combined query that will find all the documents which will be found at least for one of the original queries.
static CreatePhraseSearchQuery(params SearchQuery[]) Creates a phrase search query.
static CreateRegexQuery(string) Creates a regular expression query.
static CreateRegexQuery(string, RegexOptions) Creates a regular expression query.
static CreateWildcardQuery(int) Creates a wildcard for the phrase search.
static CreateWildcardQuery(int, int) Creates a wildcard for the phrase search.
static CreateWordPatternQuery(WordPattern) Creates a word pattern query.
static CreateWordQuery(string) Creates a simple word query.
abstract GetChild(int) Gets a child query by an index.
abstract ToString() Returns a String that represents the current SearchQuery instance.

Remarks

Learn more

Examples

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 DateTime(2011, 6, 17), new DateTime(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.SearchOptions = new SearchOptions(); // Setting search options only for subquery 3
subquery3.SearchOptions.FuzzySearch.Enabled = true;
subquery3.SearchOptions.FuzzySearch.FuzzyAlgorithm = 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.MaxOccurrenceCountPerTerm = 1000000;
options.MaxTotalOccurrenceCount = 10000000;

SearchResult result = index.Search(query, options); // Searching

See Also