我已经实施了一个Solr建议处理程序来处理来自我的应用程序的自动填充建议。但是,我需要能够根据用户权限过滤这些结果。从本质上讲,这可能是确保其中一个返回的字段与密钥(例如用户名)匹配。
我的架构看起来像这样(自动填充字段):
<!-- suggest fields -->
<field name="name_suggest" type="text_suggest" indexed="true" stored="false" multiValued="true" />
<field name="name_suggest_suggest_edge" type="text_suggest_edge" indexed="true" stored="false" multiValued="true" />
<field name="name_suggest_suggest_ngram" type="text_suggest_ngram" indexed="true" stored="false" multiValued="true" />
<field name="name_suggest_s" type="alphaNumericSort" indexed="true" stored="false" multiValued="true" />
<!-- copy fields -->
<copyField source="firstName" dest="name_suggest" />
<copyField source="firstName" dest="name_suggest_suggest_edge" />
<copyField source="firstName" dest="name_suggest_suggest_ngram" />
<copyField source="firstName" dest="name_suggest_s" />
<copyField source="lastName" dest="name_suggest" />
<copyField source="lastName" dest="name_suggest_suggest_edge" />
<copyField source="lastName" dest="name_suggest_suggest_ngram" />
<copyField source="lastName" dest="name_suggest_s" />
<copyField source="id" dest="customerID" />
SolrConfig 中的建议处理程序:
!-- request handler to return typeahead suggestions -->
<requestHandler name="/suggest" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="defType">edismax</str>
<str name="rows">10</str>
<str name="fl">firstName, lastName, address1, customerID,score</str>
<str name="qf">name_suggest^30 name_suggest_suggest_edge^50.0</str>
<str name="pf">name_suggest_suggest_edge^50.0</str>
<str name="group">false</str>
<str name="group.field">name_suggest_s</str>
<str name="sort">score desc</str>
<str name="group.sort">score desc</str>
</lst>
</requestHandler>
如何过滤来自此处理程序的结果(最好不必在内存消费者方面进行)?
答案 0 :(得分:0)
您可以过滤建议,就像过滤搜索一样。使用cfq而不是Solr fq参数。
suggest.cfq 如果建议者支持,则使用上下文过滤器查询来过滤基于上下文字段的建议。
注意:
目前仅支持上下文过滤(suggest.cfq) 仅限于AnalyzingInfixLookupFactory和BlendedInfixLookupFactory 当由Document * Dictionary支持时。所有其他实现都将 返回未过滤的匹配,就像没有请求过滤一样。
来源https://lucene.apache.org/solr/guide/6_6/suggester.html#Suggester-SuggestRequestHandlerParameters