zc.catalog

Extensions to the Zope 3 Catalog
Download

zc.catalog Ranking & Summary

Advertisement

  • Rating:
  • License:
  • ZPL
  • Publisher Name:
  • Zope Corporation and Contributors
  • Publisher web site:
  • http://zope org

zc.catalog Tags


zc.catalog Description

Extensions to the Zope 3 Catalog zc.catalog is an extension for Zope 3 catalog, Zope 3's indexing and search facility. zc.catalog contains a number of extensions to the Zope 3 catalog, such as some new indexes, improved globbing and stemming support, and an alternative catalog implementation.Value IndexThe valueindex is an index similar to, but more flexible than a standard Zope field index. The index allows searches for documents that contain any of a set of values; between a set of values; any (non-None) values; and any empty values.Additionally, the index supports an interface that allows examination of the indexed values.It is as policy-free as possible, and is intended to be the engine for indexes with more policy, as well as being useful itself.On creation, the index has no wordCount, no documentCount, and is, as expected, fairly empty. >>> from zc.catalog.index import ValueIndex >>> index = ValueIndex() >>> index.documentCount() 0 >>> index.wordCount() 0 >>> index.maxValue() # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError:... >>> index.minValue() # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError:... >>> list(index.values()) [] >>> len(index.apply({'any_of': (5,)})) 0The index supports indexing any value. All values within a given index must sort consistently across Python versions. >>> data = {1: 'a', ... 2: 'b', ... 3: 'a', ... 4: 'c', ... 5: 'd', ... 6: 'c', ... 7: 'c', ... 8: 'b', ... 9: 'c', ... } >>> for k, v in data.items(): ... index.index_doc(k, v) ...After indexing, the statistics and values match the newly entered content. >>> list(index.values()) >>> index.documentCount() 9 >>> index.wordCount() 4 >>> index.maxValue() 'd' >>> index.minValue() 'a' >>> list(index.ids()) The index supports four types of query. The first is 'any_of'. It takes an iterable of values, and returns an iterable of document ids that contain any of the values. The results are not weighted. >>> list(index.apply({'any_of':('b', 'c')})) >>> list(index.apply({'any_of': ('b',)})) >>> list(index.apply({'any_of': ('d',)})) >>> list(index.apply({'any_of':(42,)})) []Another query is 'any', If the key is None, all indexed document ids with any values are returned. If the key is an extent, the intersection of the extent and all document ids with any values is returned. >>> list(index.apply({'any': None})) >>> from zc.catalog.extentcatalog import FilterExtent >>> extent = FilterExtent(lambda extent, uid, obj: True) >>> for i in range(15): ... extent.add(i, i) ... >>> list(index.apply({'any': extent})) >>> limited_extent = FilterExtent(lambda extent, uid, obj: True) >>> for i in range(5): ... limited_extent.add(i, i) ... >>> list(index.apply({'any': limited_extent})) The 'between' argument takes from 1 to four values. The first is the minimum, and defaults to None, indicating no minimum; the second is the maximum, and defaults to None, indicating no maximum; the next is a boolean for whether the minimum value should be excluded, and defaults to False; and the last is a boolean for whether the maximum value should be excluded, and also defaults to False. The results are not weighted. >>> list(index.apply({'between': ('b', 'd')})) >>> list(index.apply({'between': ('c', None)})) >>> list(index.apply({'between': ('c',)})) >>> list(index.apply({'between': ('b', 'd', True, True)})) The 'none' argument takes an extent and returns the ids in the extent that are not indexed; it is intended to be used to return docids that have no (or empty) values. >>> list(index.apply({'none': extent})) Trying to use more than one of these at a time generates an error. >>> index.apply({'between': (5,), 'any_of': (3,)}) ... # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError:...Using none of them simply returns None. >>> index.apply({}) # returns NoneInvalid query names cause ValueErrors. >>> index.apply({'foo':()}) ... # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError:...When you unindex a document, the searches and statistics should be updated. >>> index.unindex_doc(5) >>> len(index.apply({'any_of': ('d',)})) 0 >>> index.documentCount() 8 >>> index.wordCount() 3 >>> list(index.values()) >>> list(index.ids()) Reindexing a document that has a changed value also is reflected in subsequent searches and statistic checks. >>> list(index.apply({'any_of': ('b',)})) >>> data = 'e' >>> index.index_doc(8, data) >>> index.documentCount() 8 >>> index.wordCount() 4 >>> list(index.apply({'any_of': ('e',)})) >>> list(index.apply({'any_of': ('b',)})) >>> data = 'e' >>> index.index_doc(2, data) >>> index.documentCount() 8 >>> index.wordCount() 3 >>> list(index.apply({'any_of': ('e',)})) >>> list(index.apply({'any_of': ('b',)})) []Reindexing a document for which the value is now None causes it to be removed from the statistics. >>> data = None >>> index.index_doc(3, data) >>> index.documentCount() 7 >>> index.wordCount() 3 >>> list(index.ids()) This affects both ways of determining the ids that are and are not in the index (that do and do not have values). >>> list(index.apply({'any': None})) >>> list(index.apply({'any': extent})) >>> list(index.apply({'none': extent})) The values method can be used to examine the indexed values for a given document id. For a valueindex, the "values" for a given doc_id will always have a length of 0 or 1. >>> index.values(doc_id=8) ('e',)And the containsValue method provides a way of determining membership in the values. >>> index.containsValue('a') True >>> index.containsValue('q') False Requirements: · Python · Zope What's New in This Release: · The package's configure.zcml does not include the browser subpackage's configure.zcml anymore. · This, together with browser and test_browser extras_require, decouples the browser view registrations from the main code. As a result projects that do not need the ZMI views to be registered are not pulling in the zope.app.* dependencies anymore. To enable the ZMI views for your project, you will have to do two things: · list zc.catalog as a install_requires. · have your project's configure.zcml include the zc.catalog.browser subpackage. · Only include the browser tests whenever the dependencies for the browser tests are available. · Python2.7 test fix.


zc.catalog Related Software