Skip to content

Preparing queries

Some filter parameters accept a combination of modifiers to create complex queries. For example, to search for content that mentions both Titanic and ship, you can use the AND modifier to combine these conditions:

from impresso import AND

impresso.search.find(term=AND("Titanic", "ship"))

We can refine this condition and search for all content items that mention Titanic and ship together OR mention Titanic and iceberg together AND do not mention Di Caprio.

from impresso import AND, OR

impresso.search.find(
  term=(
    AND("Titanic", "ship") | 
    AND("Titanic", "iceberg")
  ) & ~OR("Di Caprio")
)

Modifiers

impresso.structures.OR

Bases: TermSet[T], Generic[T]

Used in filters to specify that any of the terms must be present in the result.

Example:

OR(["apple", "banana"])
OR("apple")
OR("apple", "banana")
# Negate:
~OR("apple", "banana")

impresso.structures.AND

Bases: TermSet[T], Generic[T]

Used in filters to specify that all the terms must be present in the result.

Example:

AND(["apple", "banana"])
AND("apple")
AND("apple", "banana")
# Negate:
~AND("apple", "banana")

impresso.structures.DateRange

Date range.

Example:

DateRange(datetime.date(1900, 1, 1), datetime.date(2000, 12, 31))

# Everything until 2000
DateRange(None, datetime.date(2000, 12, 31))

# Everything since 1900
DateRange(datetime.date(1900, 12, 31), None)

impresso.structures.NumericRange

Date range.

Example:

NumericRange(1, 10)