caterpillar.searching.query package¶
Module Contents¶
This module implements the query framework for caterpillar.
The design intends that the BaseQuery class is extended to provide specific query functionality that can be used by IndexSearcher.
- class caterpillar.searching.query.BaseQuery¶
Bases: object
Each BaseQuery concrete class should represent an individual facet of the query API, providing query functionality in the evaluate method.
- evaluate(index)¶
Evaluate this query against the specified index.
Returns QueryResult.
Raises QueryError on exception.
- exception caterpillar.searching.query.QueryError¶
Bases: exceptions.Exception
Invalid query
- class caterpillar.searching.query.QueryResult(frame_ids, term_weights)¶
Bases: object
Encapsulates result data for a single query, which is comprised of a list of frame_ids that match the query, and term_weights, which is a dit of matched query terms to their float weightings. All weightings default to 1 unless they are modified explicitly by the query. Their purpose is to facilitate scoring a query result, based on the query that returned it.
caterpillar.searching.query.match module¶
The purpose of this module is to allow the matching of arbitrary combinations of other queries when searching. This is of particular use in combining the core query functionality of QueryStringQuery with various plugin-provided queries.
Callers should use either MatchAllQuery` or MatchSomeQuery to match the results of 1 or more BaseQuery objects.
Also note that it is possible to nest MatchAllQuery and MatchSomeQuery objects within themselves and each other.
- class caterpillar.searching.query.match.MatchAllQuery(queries, exclude_queries=None)¶
Bases: caterpillar.searching.query.match._MatchQuery
The match all query performs an intersection across a list of queries (of type BaseQuery), optionally subtracting the results of exclude_queries.
- class caterpillar.searching.query.match.MatchSomeQuery(queries, exclude_queries=None)¶
Bases: caterpillar.searching.query.match._MatchQuery
The match some query performs a union across a list of queries (of type BaseQuery), optionally excluding the results of exclude_queries.
caterpillar.searching.query.querystring module¶
This module supports all basic querying functionality in query string format, which is exposed through the QueryStringQuery class.
Examples:
- Boolean operators:
- telephone AND email – Text frames that contain both ‘telephone’ and ‘email’. telephone NOT email – Text frames that contain ‘telephone’ but not ‘email’. telephone OR email – Text frames that contain ‘telephone’ or ‘email’.
- Wildcards:
- ?mail – ‘?’ represents a single character wildcard. phon – ‘*’ represents a multiple character wildcard.
- Term Weighting:
- telephone^2 OR email – Increase the importance of the term ‘telephone’ in the query by a 2x multiplier.
- Field Equality:
- score=9 – Text frames which have ‘score’ metadata of ‘9’. (<, <=, >, >= operators supported for numeric fields)
- class caterpillar.searching.query.querystring.QueryStringQuery(query_str, text_field=None)¶
Bases: caterpillar.searching.query.BaseQuery
This class allows term and metadata based querying via raw query string passed to query_str.
Optionally restricts query to the specified text_field.