zope.index

raw JSON →
8.1 verified Fri May 01 auth: no python maintenance

Provides index implementations (field, text, set, etc.) for use with cataloging systems. Version 8.1, requires Python 3.10+. Maintenance mode.

pip install zope.index
error AttributeError: module 'zope.index' has no attribute 'FieldIndex'
cause Importing from top-level instead of submodule.
fix
Use 'from zope.index.field import FieldIndex'
error zope.interface.interface.InvalidInterface: '...' is not a valid interface
cause Incorrect interface passed to index constructor (e.g., fieldname wrong).
fix
Check that the interface attribute exists and matches the name expected by the index.
deprecated zope.index is in maintenance mode. No new features likely. Consider alternatives if starting fresh.
fix Evaluate if you need full Zope catalog stack; many use cases can be replaced with plain dicts.
gotcha After indexing, you must explicitly apply pending updates via index.updateIndex() for some index types (e.g., SetIndex) before search works.
fix Call index.updateIndex() after batch indexing operations to flush changes.

Create a FieldIndex, index two objects, search for one.

from zope.index.field import FieldIndex
index = FieldIndex()
index.index_object(1, 'value1')
index.index_object(2, 'value2')
hits = index.search({'any_of': ('value1',)})
print(hits)
# Result: {1: 1}