repoze.catalog.catalog

repoze.catalog.query

Comparators

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)

Boolean Operators

class repoze.catalog.query.Or(*queries)

Boolean Or of multiple queries.

class repoze.catalog.query.And(*queries)

Boolean And of multiple queries.

class repoze.catalog.query.Not(query)

Negation of a query.

Other Helpers

class repoze.catalog.query.Name(name)

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)
repoze.catalog.query.parse_query(expr, optimize_query=True)

Parses the given expression string and returns a query object. Requires Python >= 2.6.

repoze.catalog.indexes.field

repoze.catalog.indexes.keyword

repoze.catalog.indexes.text

repoze.catalog.indexes.facet

repoze.catalog.indexes.path

repoze.catalog.document

class repoze.catalog.document.DocumentMap

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(address, docid=())

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(docid, data)

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.

address_for_docid(docid)

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.

docid_for_address(address)

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.

get_metadata(docid)

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.

new_docid()

Return a new document id.

The returned value is guaranteed not to be used already in this document map.

remove_address(address)

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_docid(docid)

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(docid, *keys)

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.