Add an object which implements repoze.catalog.interfaces.ICatalogIndex to the catalog. No other type of object may be added to a catalog.
Retrieve an index.
Retrieve an index or return failobj.
Clear all indexes in this catalog.
Register the document represented by obj in indexes of this catalog using docid docid.
Use the arguments to perform a query. Return a tuple of (num, resultseq).
Reindex the document referenced by docid using the object passed in as obj (typically just does the equivalent of unindex_doc, then index_doc, but specialized indexes can override the method that this API calls to do less work.
Use the query terms to perform a query. Return a tuple of (num, resultseq) based on the merging of results from individual indexes.
Note
this method is deprecated as of repoze.catalog version 0.8. Use repoze.catalog.Catalog.query() instead.
Unregister the document id from indexes of this catalog.
- class repoze.catalog.query.Contains(index_name, value)¶
Contains query.
CQE equivalent: ‘foo’ in index
- class repoze.catalog.query.Eq(index_name, value)¶
Equals query.
CQE equivalent: index == ‘foo’
- class repoze.catalog.query.NotEq(index_name, value)¶
Not equal query.
CQE eqivalent: index != ‘foo’
- class repoze.catalog.query.Gt(index_name, value)¶
Greater than query.
CQE equivalent: index > ‘foo’
- class repoze.catalog.query.Lt(index_name, value)¶
Less than query.
CQE equivalent: index < ‘foo’
- class repoze.catalog.query.Ge(index_name, value)¶
Greater (or equal) query.
CQE equivalent: index >= ‘foo’
- class repoze.catalog.query.Le(index_name, value)¶
Less (or equal) query.
CQE equivalent: index <= ‘foo
- class repoze.catalog.query.Contains(index_name, value)
Contains query.
CQE equivalent: ‘foo’ in index
- class repoze.catalog.query.DoesNotContain(index_name, value)¶
CQE equivalent: ‘foo’ not in index
- class repoze.catalog.query.Any(index_name, value)¶
Any of query.
CQE equivalent: index in any([‘foo’, ‘bar’])
- class repoze.catalog.query.NotAny(index_name, value)¶
Not any of query (ie, None of query)
CQE equivalent: index not in any([‘foo’, ‘bar’])
- class repoze.catalog.query.All(index_name, value)¶
All query.
CQE equivalent: index in all([‘foo’, ‘bar’])
- class repoze.catalog.query.NotAll(index_name, value)¶
NotAll query.
CQE equivalent: index not in all([‘foo’, ‘bar’])
- class repoze.catalog.query.InRange(index_name, start, end, start_exclusive=False, end_exclusive=False)¶
Index value falls within a range.
- CQE eqivalent: lower < index < upper
- lower <= index <= upper
- class repoze.catalog.query.NotInRange(index_name, start, end, start_exclusive=False, end_exclusive=False)¶
Index value falls outside a range.
- CQE eqivalent: not(lower < index < upper)
- not(lower <= index <= upper)
A variable name in an expression, evaluated at query time. Can be used to defer evaluation of variables used inside of expressions until query time.
Example:
from repoze.catalog.query import Eq
from repoze.catalog.query import Name
# Define query at module scope
find_cats = Eq('color', Name('color')) & Eq('sex', Name('sex'))
# Use query in a search function, evaluating color and sex at the
# time of the query
def search_cats(catalog, resolver, color='tabby', sex='female'):
# Let resolver be some function which can retrieve a cat object
# from your application given a docid.
params = dict(color=color, sex=sex)
count, docids = catalog.query(find_cats, params)
for docid in docids:
yield resolver(docid)
Parses the given expression string and returns a query object. Requires Python >= 2.6.
Keyword index.
Query types supported:
Full-text index.
Query types supported:
Sort by text relevance.
This only works if the query includes at least one text query, leading to a weighted result. This method raises TypeError if the result is not weighted.
A weighted result is a dictionary-ish object that has docids as keys and floating point weights as values. This method sorts the dictionary by weight and returns the sorted docids as a list.
Facet index.
Query types supported:
Given a set of docids (usually returned from query), provide count information for further facet narrowing. Optionally omit count information for facets and their ancestors that are in ‘omit_facets’ (a sequence of facets)
Pass in an integer document id and an object supporting a sequence of facet specifiers ala [‘style:gucci:handbag’] via the discriminator
Index for model paths (tokens separated by ‘/’ characters)
A path index stores all path components of the physical path of an object.
Internal datastructure:
Query types supported:
Takes a document ID and returns all the information we have on that specific object.
Insert an entry.
comp is a path component id is the docid level is the level of the component inside the path
return the number distinct values
path is either a string representing a relative URL or a part of a relative URL or a tuple (path,level).
level >= 0 starts searching at the given level level < 0 not implemented yet
A two-way map between addresses (e.g. location paths) and document ids.
The map is a persistent object meant to live in a ZODB storage.
Additionally, the map is capable of mapping ‘metadata’ to docids.
Add a new document to the document map.
address is a string or other hashable object which represents a token known by the application.
docid, if passed, must be an int. In this case, remove any previous address stored for it before mapping it to the new address. Passing an explicit docid also removes any metadata associated with that docid.
If docid is not passed, generate a new docid.
Return the integer document id mapped to address.
Add metadata related to a given document id.
data must be a mapping, such as a dictionary.
For each key/value pair in data insert a metadata key/value pair into the metadata stored for docid.
Overwrite any existing values for the keys in data, leaving values unchanged for other existing keys.
Raise a KeyError If docid doesn’t relate to an address in the document map.
Retrieve an address for a given document id.
docid is an integer document id.
Return the address corresponding to docid.
If docid doesn’t exist in the document map, return None.
Retrieve a document id for a given address.
address is a string or other hashable object which represents a token known by the application.
Return the integer document id corresponding to address.
If address doesn’t exist in the document map, return None.
Return the metadata for docid.
Return a mapping of the keys and values set using add_metadata.
Raise a KeyError If metadata does not exist for docid.
Return a new document id.
The returned value is guaranteed not to be used already in this document map.
Remove a document from the document map using an address.
address is a string or other hashable object which represents a token known by the application.
Remove any corresponding metadata for address as well.
Return a True if address existed in the map, else return False.
Remove a document from the document map for the given document ID.
docid is an integer document id.
Remove any corresponding metadata for docid as well.
Return a True if docid existed in the map, else return False.
Remove metadata related to a given document id.
If docid doesn’t exist in the metadata map, raise a KeyError.
For each key in keys, remove the metadata value for the docid related to that key.
Do not raise any error if no value exists for a given key.
If no keys are specified, remove all metadata related to the docid.