好,感謝sdupton的建議,我找到了一種方法使其工作。
這是溶液(省略明顯進口):
from Products.AdvancedQuery import (Eq, Not, In,
RankByQueries_Sum, MatchGlob)
from my.product.interfaces import IQuery
class CatalogQuery(object):
implements(IQuery)
...
def _search(self, q, limit):
"""Perform the Catalog search on the 'SearchableText' index
using phrase 'q', and filter any content types
blacklisted as 'unsearchable' in the '@@search-controlpanel'.
"""
# ask the portal_properties tool for a list of names of
# unsearchable content types
ptool = getToolByName(self.context, 'portal_properties')
types_not_searched = ptool.site_properties.types_not_searched
# define the search ranking strategy
rs = RankByQueries_Sum(
(Eq('Title', q), 16),
(Eq('Description', q), 8)
)
# tune the normalizer
norm = 1 + rs.getQueryValueSum()
# prepare the search glob
glob = "".join((q, "*"))
# build the query statement, filter using unsearchable list
query = MatchGlob('SearchableText', glob) & Not(
In('portal_type', types_not_searched)
)
# perform the search using the portal catalog tool
brains = self._ctool.evalAdvancedQuery(query, (rs,))
return brains[:limit], norm
感謝您的指針。您幫助我瞭解如何使其發揮作用。我添加了一個描述我的解決方案的回覆。 – zedr