repoze.catalog.catalog

class repoze.catalog.catalog.Catalog(family=None)
__setitem__(name, index)

Add an object which implements repoze.catalog.interfaces.ICatalogIndex to the catalog. No other type of object may be added to a catalog.

__getitem__(key)

Retrieve an index.

get(key, failobj=None)

Retrieve an index or return failobj.

clear()

Clear all indexes in this catalog.

index_doc(docid, obj)

Register the document represented by obj in indexes of this catalog using docid docid.

query(queryobject, sort_index=None, limit=None, sort_type=None, reverse=False, names=None)

Use the arguments to perform a query. Return a tuple of (num, resultseq).

reindex_doc(docid, obj)

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.

search(**query)

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.

unindex_doc(docid)

Unregister the document id from indexes of this 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

class repoze.catalog.indexes.field.CatalogFieldIndex(discriminator)

Field indexing.

Query types supported:

  • Eq
  • NotEq
  • Gt
  • Ge
  • Lt
  • Le
  • In
  • NotIn
  • Any
  • NotAny
  • InRange
  • NotInRange
unindex_doc(docid)

See interface IInjection.

Base class overridden to be able to unindex None values.

repoze.catalog.indexes.keyword

class repoze.catalog.indexes.keyword.CatalogKeywordIndex(discriminator)

Keyword index.

Query types supported:

  • Eq
  • NotEq
  • In
  • NotIn
  • Any
  • NotAny
  • All
  • NotAll

repoze.catalog.indexes.text

class repoze.catalog.indexes.text.CatalogTextIndex(discriminator, lexicon=None, index=None)

Full-text index.

Query types supported:

  • Contains
  • DoesNotContain
  • Eq
  • NotEq
sort(result, reverse=False, limit=None, sort_type=None)

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.

repoze.catalog.indexes.facet

class repoze.catalog.indexes.facet.CatalogFacetIndex(discriminator, facets, family=None)

Facet index.

Query types supported:

  • Eq
  • NotEq
  • In
  • NotIn
  • Any
  • NotAny
  • All
  • NotAll
counts(docids, omit_facets=())

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)

index_doc(docid, object)

Pass in an integer document id and an object supporting a sequence of facet specifiers ala [‘style:gucci:handbag’] via the discriminator

repoze.catalog.indexes.path

class repoze.catalog.indexes.path.CatalogPathIndex(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:

  • a physical path of an object is split into its components
  • every component is kept as a key of a OOBTree in self._indexes
  • the value is a mapping ‘level of the path component’ to ‘all docids with this path component on this level’

Query types supported:

  • Eq
  • NotEq
apply(query)
applyEq(query)
getEntryForObject(docid)

Takes a document ID and returns all the information we have on that specific object.

insertEntry(comp, id, level)

Insert an entry.

comp is a path component id is the docid level is the level of the component inside the path

numObjects()

return the number distinct values

search(path, default_level=0)

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

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.