create_not_query method

create_not_query

Creates an inverted query that matches all documents not matching the specified query.

def create_not_query(cls, query):
    ...
Parameter Type Description
query SearchQuery The query to invert.

Returns: A combined NOT query.

Example

from groupdocs.search import SearchQuery

# Create a word query for "Einstein"
einstein_query = SearchQuery.create_word_query("Einstein")

# Invert the query to find documents that do NOT contain "Einstein"
not_query = SearchQuery.create_not_query(einstein_query)

# Combine with another query using AND
relativity_query = SearchQuery.create_word_query("relativity")
combined_query = SearchQuery.create_and_query(relativity_query, not_query)

# Execute the search
results = index.search(combined_query)

See Also