Home | Trees | Indices | Help |
---|
|
1 """RelatedIndex is an index for the catalog that does not index 2 anything. 3 4 Instead, the _apply_index performs a query to a thesaurus object for 5 related words of the keyword parameters and then queries the site 6 catalog for the result of the thesaurus query. 7 """ 8 9 from logging import getLogger 10 11 from zope.interface import implements 12 from zope.component import queryUtility 13 from zope.i18n.interfaces import IUserPreferredLanguages 14 15 from Globals import Persistent, DTMLFile 16 from OFS.SimpleItem import SimpleItem 17 from BTrees.IIBTree import IITreeSet, IISet, intersection, union 18 19 from Products.PluginIndexes import PluggableIndex 20 from Products.PluginIndexes.common.util import parseIndexRequest 21 from Products.PluginIndexes.interfaces import IPluggableIndex 22 23 from Products.CMFCore.utils import getToolByName 24 25 from platecom.ontocatalog.indexes import utils 26 2729 """An index for related words that does not index anything""" 30 31 __implements__ = (PluggableIndex.PluggableIndexInterface,) 32 implements(IPluggableIndex) 33 34 meta_type = "RelatedIndex" 35 manage_workspace = DTMLFile('dtml/manageFakeIndex', globals()) 36 41 47 53104 105 106 manage_addRelatedIndexForm = DTMLFile('dtml/addFakeIndex', globals()) 107 11355 """Apply the index to query parameters given in the argument, 56 request. 57 58 The argument should be a mapping object. 59 60 If the request does not contain the needed parameters, then 61 None is returned. 62 63 Otherwise two objects are returned. The first object is a 64 ResultSet containing the record numbers of the matching 65 records. The second object is a tuple containing the names of 66 all data fields used. 67 """ 68 portal = getToolByName(self, 'portal_url').getPortalObject() 69 query_options = ('query', 'context') 70 record = parseIndexRequest(request, self.id, query_options) 71 if record.keys is None: 72 return None 73 74 #Languages dance 75 langutil = queryUtility(IUserPreferredLanguages, 76 name='platecom_preferred_languages') 77 user_languages = tuple(langutil.getPreferredLanguages(request=self.REQUEST)) 78 79 context = record.get('context', None) 80 81 if context is not None: 82 context = context + '@' + user_language 83 84 thesaurus_results = [] 85 catalog_results = () 86 for k in record.keys: 87 for lang in user_languages: 88 key = '%s@%s' % (k, lang) 89 thesaurus_results += utils.get_related(portal, key, 90 lang=user_languages, 91 context=context) 92 93 if thesaurus_results != []: 94 tuples = [tl.split('@') for tl in thesaurus_results] 95 related = ['\"%s\"' % (t,) for (t,l) in tuples] 96 search_text = ' OR '.join(related) 97 query = {'SearchableText': search_text, 98 'Language': user_languages} 99 catalog_results += tuple(self.catalog(query)) 100 101 result = utils.build_catalog_results(self.id, self.catalog._catalog, 102 catalog_results) 103 return result
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Tue May 20 01:54:35 2008 | http://epydoc.sourceforge.net |