{ "info": { "author": "Dan Korostelev and Zope Community", "author_email": "zope-dev@zope.org", "bugtrack_url": null, "classifiers": [], "description": "===================\nz3c.multifieldindex\n===================\n\nThis package provides an index for zope catalog that can index multiple fields.\nIt is useful in cases when field set are dynamic (for example with customizable\npersistent fields).\n\nActually, this package provides a base class for custom multi-field indexes and\nto make it work, you need to override some methods in it. But first, let's\ncreate a content schema and interface we will use:\n\n >>> from zope.interface import Interface, implements\n >>> from zope.schema import Text, Int, List, TextLine\n \n >>> class IPerson(Interface):\n ...\n ... age = Int()\n ... info = Text()\n ... skills = List(value_type=TextLine())\n\n >>> class Person(object):\n ...\n ... implements(IPerson)\n ...\n ... def __init__(self, age, info, skills):\n ... self.age = age\n ... self.info = info\n ... self.skills = skills\n\nLet's create a set of person objects:\n\n >>> dataset = [\n ... (1, Person(20, u'Sweet and cute', ['dancing', 'singing'])),\n ... (2, Person(33, u'Smart and sweet', ['math', 'dancing'])),\n ... (3, Person(6, u'Young and cute', ['singing', 'painting'])),\n ... ]\n\nWe have choose exactly those different types of fields to illustrate that the\nindex is smart enough to know how to index each type of value. We'll return\nback to this topic later in this document.\n\nNow, we need to create an multi-field index class that will be used to index our\nperson objects. We'll override two methods in it to make it functional:\n\n >>> from z3c.multifieldindex.index import MultiFieldIndexBase\n >>> from zope.schema import getFields\n\n >>> class PersonIndex(MultiFieldIndexBase):\n ...\n ... def _fields(self):\n ... return getFields(IPerson).items()\n ... \n ... def _getData(self, object):\n ... return {\n ... 'age': object.age,\n ... 'info': object.info,\n ... 'skills': object.skills,\n ... }\n\nThe \"_fields\" method should return an iterable of (name, field) pairs of fields\nthat should be indexed. The sub-indexes will be created for those fields.\n\nThe \"_getData\" method returns a dictionary of data to be indexed using given\nobject. The keys of the dictionary should match field names.\n\nSub-indexes are created automatically by looking up an index factory for each\nfield. Three most-used factories are provided by this package. Let's register\nthem to continue (it's also done in this package's configure.zcml file):\n\n >>> from z3c.multifieldindex.subindex import DefaultIndexFactory\n >>> from z3c.multifieldindex.subindex import CollectionIndexFactory\n >>> from z3c.multifieldindex.subindex import TextIndexFactory\n >>> from zope.component import provideAdapter\n \n >>> provideAdapter(DefaultIndexFactory)\n >>> provideAdapter(CollectionIndexFactory)\n >>> provideAdapter(TextIndexFactory)\n\nThe default index factory creates zc.catalog's ValueIndex, the collection index\nfactory creates zc.catalog's SetIndex and the text index factory creates\nzope.index's TextIndex. This is needed to know when you'll be doing queries.\n\nOkay, now let's create an instance of index and prepare it to be used.\n\n >>> index = PersonIndex()\n >>> index.recreateIndexes()\n\nThe \"recreateIndexes\" does re-creation of sub-indexes. It is normally called\nby a subscriber to IObjectAddedEvent, provided by this package, but we simply\ncall it by hand for this test.\n\nNow, let's finally index our person objects:\n\n >>> for docid, person in dataset:\n ... index.index_doc(docid, person)\n\nLet's do a query now. The query format is quite simple. It is a dictionary, where\nkeys are names of fields and values are queries for sub-indexes.\n\n >>> results = index.apply({\n ... 'skills': {'any_of': ('singing', 'painting')},\n ... })\n >>> list(results)\n [1, 3]\n\n >>> results = index.apply({\n ... 'info': 'sweet',\n ... })\n >>> list(results)\n [1, 2]\n\n >>> results = index.apply({\n ... 'age': {'between': (1, 30)},\n ... })\n >>> list(results)\n [1, 3]\n\n >>> results = index.apply({\n ... 'age': {'between': (1, 30)},\n ... 'skills': {'any_of': ('dancing', )},\n ... })\n >>> list(results)\n [1]\n\n\n=======\nCHANGES\n=======\n\n3.4.0 (15-10-2009)\n------------------\n\n- Initial release (using Zope 3.4 dependencies).", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/z3c.multifieldindex", "keywords": null, "license": "ZPL 2.1", "maintainer": null, "maintainer_email": null, "name": "z3c.multifieldindex", "package_url": "https://pypi.org/project/z3c.multifieldindex/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/z3c.multifieldindex/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/z3c.multifieldindex" }, "release_url": "https://pypi.org/project/z3c.multifieldindex/3.4.0/", "requires_dist": null, "requires_python": null, "summary": "Multi-field index for zope catalog", "version": "3.4.0" }, "last_serial": 802056, "releases": { "3.4.0": [ { "comment_text": "", "digests": { "md5": "33ba724ad25ffded2543ba6ee80c9552", "sha256": "6408592f2ccdc8b94b09a7bc601332dfd5e7f15ece437d377a85f406ea835103" }, "downloads": -1, "filename": "z3c.multifieldindex-3.4.0.tar.gz", "has_sig": false, "md5_digest": "33ba724ad25ffded2543ba6ee80c9552", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6061, "upload_time": "2009-10-15T18:01:43", "url": "https://files.pythonhosted.org/packages/2a/bb/ce571e83cb4a4f1092560a4d641ab3819177540031df473c3789e7e18223/z3c.multifieldindex-3.4.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "33ba724ad25ffded2543ba6ee80c9552", "sha256": "6408592f2ccdc8b94b09a7bc601332dfd5e7f15ece437d377a85f406ea835103" }, "downloads": -1, "filename": "z3c.multifieldindex-3.4.0.tar.gz", "has_sig": false, "md5_digest": "33ba724ad25ffded2543ba6ee80c9552", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6061, "upload_time": "2009-10-15T18:01:43", "url": "https://files.pythonhosted.org/packages/2a/bb/ce571e83cb4a4f1092560a4d641ab3819177540031df473c3789e7e18223/z3c.multifieldindex-3.4.0.tar.gz" } ] }