{ "info": { "author": "Souheil Chelfouh", "author_email": "trollfot@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Zope3", "License :: OSI Approved :: GNU General Public License (GPL)", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "=================\ndolmen.app.search\n=================\n\n`dolmen.app.search` provides components to search objects inside a\nGrok application.\n\nSearchers\n=========\n\n`dolmen.app.search` introduces a new component : the ISearcher. This\ncomponent is dedicated in searching and returning a set of objects,\nusing a search term.\n\nThe provided API is::\n\n >>> from dolmen.app.search.interfaces import ISearchAPI\n >>> interfaceDescription(ISearchAPI)\n ISearcher: A component dedicated to search\n ICatalogSearcher: A specialized ISearcher querying a catalog\n\n\nTest environment\n----------------\n\nIn order to test our searchers, we need an operationnal application\nwith at least one index.\n\nWe prepare out imports::\n\n >>> import grok\n >>> from grok import index\n >>> from zope.index.text.interfaces import ISearchableText\n >>> from zope.interface import Interface\n >>> from zope.schema import TextLine\n\nWe create a model that will be cataloged::\n\n >>> class IRipper(Interface):\n ... \"\"\"A serial killer.\n ... \"\"\"\n ... searchabletext = TextLine(title=u\"Name of the ripper\")\n\n >>> class Ripper(grok.Model):\n ... grok.implements(IRipper)\n ...\n ... def __init__(self, searchabletext):\n ... self.searchabletext = searchabletext\n\nWe create a Grok application, that will be out site manager::\n\n >>> class Backstreet(grok.Container, grok.Application):\n ... \"\"\"A dark alley.\n ... \"\"\"\n\n >>> grok.testing.grok_component('application', Backstreet)\n True\n\nWe define an index that will be the base for our search::\n\n >>> class RipperIndexes(grok.Indexes):\n ... grok.site(Backstreet)\n ... grok.context(IRipper)\n ... searchabletext = index.Text()\n\n >>> grok.testing.grok_component('indexes', RipperIndexes)\n True\n\nNow we persist our application and set it as the default site::\n\n >>> from zope.site.hooks import setSite\n >>> app = Backstreet()\n >>> root = getRootFolder()\n >>> root['berner_street'] = app\n \n >>> setSite(app)\n\nThe Grok application has created the catalog::\n\n >>> from zope.component import getUtility\n >>> from zope.catalog.interfaces import ICatalog\n >>> catalog = getUtility(ICatalog)\n >>> catalog\n \n\nOur index is there::\n\n >>> catalog['searchabletext']\n \n >>> catalog['searchabletext'].documentCount()\n 0\n\nIndexing\n--------\n\nThe catalog is ready. Now, if we create a content and persist it, the\ncataloging mechanism will do the work for us::\n\n >>> jack = Ripper(u\"Jack the knife\")\n >>> grok.notify(grok.ObjectCreatedEvent(jack))\n >>> app['jack'] = jack\n\n >>> catalog['searchabletext'].documentCount()\n 1\n\nThe searchabletext is set. That is what is cataloged in our site catalog::\n\n >>> jack.searchabletext\n u'Jack the knife'\n\n\nSearching\n---------\n\nAn ISearcher can be used as an utility. `dolmen.app.search` provides a\ndefault implementation of an ICatalogSearcher. This component is used\nto query the site catalog:: \n\n >>> from dolmen.app.search import ICatalogSearcher\n >>> searcher = getUtility(ICatalogSearcher, \"searcher.sitecatalog\")\t\n >>> searcher\n \n >>> searcher.catalog == catalog\n True\n\nThe search method of the ICatalogSearcher takes a search term and the\nname of the index. By default, it uses the `searchabletext` index::\n\n >>> result = searcher.search(term=\"Jack\")\n >>> result\n \n >>> list(result)\n []\n\nIf we provide a non existing index name, an error is raised::\n\n >>> result = searcher.search(term=\"Jack\", index=\"non-existing\")\n Traceback (most recent call last):\n ...\n ValueError: Index 'non-existing' does not exist\n\n\nWildcard\n~~~~~~~~\n\nA wildcard can be given, when searching a text index::\n\n >>> result = searcher.search(\"Ja\")\n >>> list(result)\n []\n\n >>> result = searcher.search(\"Ja*\")\n >>> list(result)\n []\n\n\nPermission\n~~~~~~~~~~\n\nBy default, our searcher checks the `zope.View` permission on the\nobjects of the result set. We can provide another permission\nexplicitly::\n\n >>> result = searcher.search(\"knife\", permission=\"i-do-not-exist\")\n >>> list(result)\n []\n\nA `grok.Permision` class can be used instead of a string::\n\n >>> from dolmen.app.security import CanViewContent\n >>> result = searcher.search(\"knife\", permission=CanViewContent)\n >>> list(result)\n []\n\nIf permission is set to None, nothing is checked::\n \n >>> result = searcher.search(\"knife\", permission=None)\n >>> list(result)\n []\n\n\nView and viewlet\n================\n\n`dolmen.app.search` comes with two browser components. A search form\nviewlet and a result page.\n\nSearch viewlet\n--------------\n\nA search viewlet is registered to display a search form input. In\norder to test the output of the viewlet, we need a view::\n\n >>> class GasLamp(grok.View):\n ... \"\"\"A view where the air's cold and damp\n ... \"\"\"\n ... grok.context(IRipper)\n\n >>> grok.testing.grok_component('view', GasLamp)\n True\n\nWe get the view to render the viewlet:: \n \n >>> from zope.publisher.browser import TestRequest\n >>> from zope.component import getMultiAdapter\n\n >>> request = TestRequest()\n >>> view = getMultiAdapter((jack, request), name=\"gaslamp\")\n\nThe `Search` viewlet is registered for the `dolmen.app.layout.Top`\nmanager. We construct this manager::\n\n >>> from dolmen.app.layout import Top\n >>> manager = Top(jack, request, view)\n\nWe can now call, update and render the Search viewlet::\n\n >>> from dolmen.app.search.browser import Search\n >>> search = Search(jack, request, view, manager)\n >>> search.update()\n >>> print search.render()\n
\n \n \n
\n\n\nResult page\n-----------\n\nThe viewlet posts the data to the `search.result` view. This view\nfetches the `search_term` from the request, queries the\nICatalogSearcher and displays the results::\n\n >>> request = TestRequest(form = {'search_term': 'jack'})\n >>> results = getMultiAdapter((jack, request), name=\"search.result\")\n >>> results\n \n\n >>> results.update()\n >>> print results.content()\n
\n
\n

Search

\n

Found 1 results for jack

\n
\n
\n
\n \n jack\n \n
\n
\n
\n\n\nChangelog\n=========\n\n0.4 (2010-11-05)\n----------------\n\n- The package now works for Grok 1.2.\n\n- The icon is now using the \"icon\" and no longer \"contenttype_icon\" view.\n\n- The dependencies have been reviewed and slimmed down.\n\n\n0.3.1 (2010-07-24)\n------------------\n\n- 0.3 release was broken because of missing locales directory.\n\n\n0.3 (2010-07-24)\n----------------\n\n- Added French translation.\n\n\n0.2.2 (2009-01-08)\n------------------\n\n- Declare all dependencies and some cleanup.\n\n- Require dolmen.content.View permission for Search viewlet.\n\n\n0.2.1 (2009-12-01)\n------------------\n\n- Removed all imports from zope.app.* for intid and catalog. Using now\n the new packages. This makes dolmen.app.search compatible with\n grok1.1a2.\n\n\n0.2 (2009-12-01)\n----------------\n\n- Modified the imports to make it compatible with grok 1.1 (ztk 1.0)\n\n\n0.1 (2009-11-08)\n----------------\n\n- Initial release", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://gitweb.dolmen-project.org", "keywords": "Grok Zope3 CMS Dolmen", "license": "GPL", "maintainer": null, "maintainer_email": null, "name": "dolmen.app.search", "package_url": "https://pypi.org/project/dolmen.app.search/", "platform": "Any", "project_url": "https://pypi.org/project/dolmen.app.search/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://gitweb.dolmen-project.org" }, "release_url": "https://pypi.org/project/dolmen.app.search/0.4/", "requires_dist": null, "requires_python": null, "summary": "Catalog search utilities for Grok applications", "version": "0.4" }, "last_serial": 791321, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "aefc6b28545b2e573a114f06793b3556", "sha256": "713c45d13f9fcc4c07b9797e6f2420af7e95e900c1e57f2d91aa167e4c492812" }, "downloads": -1, "filename": "dolmen.app.search-0.1.tar.gz", "has_sig": false, "md5_digest": "aefc6b28545b2e573a114f06793b3556", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7314, "upload_time": "2009-11-08T17:26:08", "url": "https://files.pythonhosted.org/packages/1e/a5/85f187e752ada9603d1b1fbe72e316b55cd7beccbd2b277577fe55db01da/dolmen.app.search-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "55b186b974c91f6c1eeb4e109843841d", "sha256": "45f92cb5dd2b61955c7ab6eb1c3f10db960bafc913f87b0b9f60b87b0c1eeef9" }, "downloads": -1, "filename": "dolmen.app.search-0.2.tar.gz", "has_sig": false, "md5_digest": "55b186b974c91f6c1eeb4e109843841d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7424, "upload_time": "2009-12-01T19:36:10", "url": "https://files.pythonhosted.org/packages/22/0e/2d625ab9d1798153a10a641833a92d2d719bfb44c356e85292fd6ea71f79/dolmen.app.search-0.2.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "7ef9209bae03d32c7387ea8d0392c4a3", "sha256": "36f761b3a54f4d75de820b362b78bcda7e589219971813012174cec4293b09d2" }, "downloads": -1, "filename": "dolmen.app.search-0.2.1.tar.gz", "has_sig": false, "md5_digest": "7ef9209bae03d32c7387ea8d0392c4a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7563, "upload_time": "2009-12-01T19:41:02", "url": "https://files.pythonhosted.org/packages/78/77/67e3c9ce897818ba50f6eb78c428967d3ccf3e18d611bf387972a8f67ca7/dolmen.app.search-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "4e5c2b4209b286ec7c69b139908df965", "sha256": "a9f13c891249d6d03901e873f46bb0b044839058a8c3ed924465c7db462c72f4" }, "downloads": -1, "filename": "dolmen.app.search-0.2.2.zip", "has_sig": false, "md5_digest": "4e5c2b4209b286ec7c69b139908df965", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17925, "upload_time": "2010-01-08T14:35:43", "url": "https://files.pythonhosted.org/packages/fe/91/7ad16e83ce68fd5dd4791d863f24ab7e1201a7f20afba5a3b901f6c03913/dolmen.app.search-0.2.2.zip" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "b42fd272bc20bfcfba6bd771f7dce2e5", "sha256": "964689c98c7adb3d4a30da80ecd53b6310a38d40df74949398b8a4ec69001314" }, "downloads": -1, "filename": "dolmen.app.search-0.3.zip", "has_sig": false, "md5_digest": "b42fd272bc20bfcfba6bd771f7dce2e5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18121, "upload_time": "2010-07-24T17:30:58", "url": "https://files.pythonhosted.org/packages/88/a4/1a0c67fba0ff80ebe0d8118d3d7f10411ab8c84a477574d92f316a455d43/dolmen.app.search-0.3.zip" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "7e5287e39cc9f6d2f81c7a4248af89fa", "sha256": "79564a75ef9174f8f2fb65fc1764f02d43cd2aa5131ccb4017f01f59bf9674d6" }, "downloads": -1, "filename": "dolmen.app.search-0.3.1.zip", "has_sig": false, "md5_digest": "7e5287e39cc9f6d2f81c7a4248af89fa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21189, "upload_time": "2010-07-24T17:56:25", "url": "https://files.pythonhosted.org/packages/5d/74/f2c84a45785431f624eabd45323f3ba819be3b87f85faed5f02d609ba291/dolmen.app.search-0.3.1.zip" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "9bd72d96af1a7577c0e1a65e286157a3", "sha256": "4e45c2dc65070276859bc87fa1e26eae492a9221794ec6251ed862ec86d9f03c" }, "downloads": -1, "filename": "dolmen.app.search-0.4.tar.gz", "has_sig": false, "md5_digest": "9bd72d96af1a7577c0e1a65e286157a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9821, "upload_time": "2010-11-05T19:52:02", "url": "https://files.pythonhosted.org/packages/ca/4c/233e4384afeaeb0d02fc8b5ec0174104cda9d8bf4692c21bb93104e7b395/dolmen.app.search-0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9bd72d96af1a7577c0e1a65e286157a3", "sha256": "4e45c2dc65070276859bc87fa1e26eae492a9221794ec6251ed862ec86d9f03c" }, "downloads": -1, "filename": "dolmen.app.search-0.4.tar.gz", "has_sig": false, "md5_digest": "9bd72d96af1a7577c0e1a65e286157a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9821, "upload_time": "2010-11-05T19:52:02", "url": "https://files.pythonhosted.org/packages/ca/4c/233e4384afeaeb0d02fc8b5ec0174104cda9d8bf4692c21bb93104e7b395/dolmen.app.search-0.4.tar.gz" } ] }