SearchQuery class

SearchQuery class

Represents a search query in object form.

Learn more:

The SearchQuery type exposes the following members:

Methods

Method Description
create_and_query Creates a combined query that will find only documents which will be found for each original query.
create_and_query Creates a combined query that will find only documents which will be found for each original query.
create_date_range_query Creates a date range query.
create_field_query Adds a field to the specified query.
create_not_query Creates an inverted query that matches all documents not matching the specified query.
create_numeric_range_query Creates a numeric range query.
create_or_query Creates a combined query that will find all the documents which will be found at least for one of the original queries.
create_or_query Creates a combined query that finds documents matching at least one of the original queries.
create_phrase_search_query Creates a phrase search query.
create_regex_query Creates a regular expression query.
create_regex_query Creates a regular expression query.
create_wildcard_query Creates a wildcard for the phrase search.
create_wildcard_query Creates a wildcard for the phrase search.
create_word_pattern_query Creates a word pattern query.
create_word_query Creates a simple word query.
get_child Gets a child query by its index.
to_string Returns a str that represents the current SearchQuery instance.

Properties

Property Description
child_count The number of child queries.
field_name The field name.
first_child The first child query.
search_options The search options of this search query.
second_child The second child query.

Example

import datetime
from groupdocs.search import Index, SearchQuery
from groupdocs.search.options import SearchOptions, TableDiscreteFunction

# Create an index and add documents
index_folder = "./MyIndex"
documents_folder = "./documents"
index = Index(index_folder)
index.add(documents_folder)

# Create subqueries
subquery1 = SearchQuery.create_date_range_query(
    datetime.datetime(2011, 6, 17), datetime.datetime(2013, 1, 1)
)
subquery2 = SearchQuery.create_wildcard_query(0, 2)
subquery3 = SearchQuery.create_word_query("birth")
subquery3.search_options = SearchOptions()
subquery3.search_options.fuzzy_search.enabled = True
subquery3.search_options.fuzzy_search.fuzzy_algorithm = TableDiscreteFunction(1)

# Combine subqueries into a phrase search query
query = SearchQuery.create_phrase_search_query(subquery1, subquery2, subquery3)

# Set overall search options
options = SearchOptions()
options.max_occurrence_count_per_term = 1_000_000
options.max_total_occurrence_count = 10_000_000

# Execute the search
result = index.search(query, options)

Guides

Task guides that use SearchQuery:

See Also