简体   繁体   English

Apache Solr:用于过滤搜索结果的按位操作

[英]Apache Solr: bitwise operations to filter search results

I need to filter solr search results corresponding the access rights in our cms (drupal 7 + custom access control mechanism based on bitmasks). 我需要过滤与我们的cms中的访问权限相对应的solr搜索结果(drupal 7 +基于位掩码的自定义访问控制机制)。

There exists a Solr QParserPlugin plugin for search results filtering based on bitwise operations on integer fields: https://issues.apache.org/jira/browse/SOLR-1913 . 存在一个Solr QParserPlugin插件,用于基于整数字段的按位运算进行搜索结果过滤: https ://issues.apache.org/jira/browse/SOLR-1913。

I am using Solr 3.6.1 (+ the plugin in /var/lib/tomcat6/solr/lib/bitwise_filter_plugin.jar) on tomcat6 (on debian system) with the schema.xml provided by the drupal module search_api_solr and the solrconfig.xml found in the modules issue queue (extended as indicated in the SOLR-1913 issue). 我使用的Solr 3.6.1(+在/var/lib/tomcat6/solr/lib/bitwise_filter_plugin.jar插件)上的tomcat6(Debian系统上)与schema.xml中由drupal的模块search_api_solr和solrconfig.xml中提供在模块发布队列中找到(扩展,如SOLR-1913问题中所示)。

The Solr query ... Solr查询......

http://solr:8080/solr/select?qf=t_title&fl=*,score&fq={!bitwise field=is_bitmask op=AND source=1234}*

... fails with the following message in the error log: ...失败并在错误日志中显示以下消息:

Sep 27, 2012 8:57:41 AM org.apache.solr.core.SolrCore execute
INFO: [] webapp=/solr path=/select params={qf=t_title&fl=*,score&fq={!bitwise+field%3Dis_bitmask+op%3DAND+source%3D1234}} status=500 QTime=15 
Sep 27, 2012 8:57:41 AM org.apache.solr.common.SolrException log
SEVERE: java.lang.NullPointerException
  at org.apache.lucene.search.FilteredQuery.hashCode(FilteredQuery.java:268)
  at java.util.AbstractList.hashCode(AbstractList.java:542)
  at org.apache.solr.search.QueryResultKey.<init>(QueryResultKey.java:49)
  at org.apache.solr.search.SolrIndexSearcher.getDocListC(SolrIndexSearcher.java:1084)
  at org.apache.solr.search.SolrIndexSearcher.search(SolrIndexSearcher.java:375)
  at org.apache.solr.handler.component.QueryComponent.process(QueryComponent.java:394)
  at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:186)
  at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:129)
  at org.apache.solr.core.SolrCore.execute(SolrCore.java:1376)
  at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:365)
  at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:260)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
  at java.lang.Thread.run(Thread.java:636)

The only thing I can see in the error message is that the plugin is invoked by solr. 我在错误消息中唯一能看到的是插件是由solr调用的。

Any help would be appreciated, Thanks. 任何帮助将不胜感激,谢谢。

Instead of making Solr do it your way, you might want to try it Solr's way. 而不是让Solr按照你的方式去做,你可能想要尝试Solr的方式。 Solr already implements boolean logic. Solr已经实现了布尔逻辑。

Split your bitfield into a set of named boolean fields. 将您的位域拆分为一组命名的布尔字段。 They can even be bit_0, bit_1, etc. if you are short on inspiration. 如果你缺乏灵感,它们甚至可以是bit_0,bit_1等。 You can use a dynamic field to save typing and allow later expansion. 您可以使用动态字段来保存键入并允许以后扩展。

Index them as bit_0:true and so on for each doc. 将它们索引为bit_0:true,依此类推每个doc。

Use those fields in the filter query to do selection: bit_0:true AND bit_24:true. 使用筛选器查询中的这些字段进行选择:bit_0:true AND bit_24:true。

This is likely to run much, much faster than a bitwise comparison on each field. 这可能比每个字段的按位比较运行得快得多。 The bitwise comparise probably needs a full table scan on each query. 按位比较可能需要对每个查询进行全表扫描。 Well, full field value scan, since Solr does not have tables. 好吧,全场值扫描,因为Solr没有表格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM