Search 获取Plone 4中可搜索内容类型的列表
我正在使用Products.AdvancedQuery为我的站点构建一个替代的LiveSearch机制。到目前为止,一切都很正常,但标准查询对所有可用的内容类型执行搜索,包括在@@search控制面板中标记为不可搜索的内容类型 我希望AdvancedQuery根据@@search控制面板中指定的内容动态筛选出不可搜索的内容。我该怎么做Search 获取Plone 4中可搜索内容类型的列表,search,plone,catalog,Search,Plone,Catalog,我正在使用Products.AdvancedQuery为我的站点构建一个替代的LiveSearch机制。到目前为止,一切都很正常,但标准查询对所有可用的内容类型执行搜索,包括在@@search控制面板中标记为不可搜索的内容类型 我希望AdvancedQuery根据@@search控制面板中指定的内容动态筛选出不可搜索的内容。我该怎么做 如果AQ不能做到这一点,我可以在查询目录后立即过滤结果。我需要一个标记为可搜索的内容类型名称(或接口)列表。如何获取这样的列表?假设您可以通过编程方式获取控制面板
如果AQ不能做到这一点,我可以在查询目录后立即过滤结果。我需要一个标记为可搜索的内容类型名称(或接口)列表。如何获取这样的列表?假设您可以通过编程方式获取控制面板黑名单中的元组或类型列表,这可能非常简单(忽略导入):
假设您可以通过编程方式获取控制面板黑名单中的元组或类型列表,这可能非常简单(忽略导入):
好的,多亏了斯达普顿的建议,我找到了一个办法让它发挥作用 这就是解决方案(省略了明显的导入):
好的,多亏了斯达普顿的建议,我找到了一个办法让它发挥作用 这就是解决方案(省略了明显的导入):
谢谢你的指点。你帮助我明白了该怎么做才能让它工作。我正在添加一个描述我的解决方案的回复。谢谢你的指点。你帮助我明白了该怎么做才能让它工作。我正在添加一个描述我的解决方案的回复。
>>> query = myquery & AdvancedQuery.Not(AdvancedQuery.In(MY_TYPE_BLACKLIST_HERE))
>>> result = getToolByName(context, 'portal_catalog').evalAdvancedQuery(query)
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