使用OR和连接查询结果导致NullPointerException

时间:2015-11-30 10:36:54

标签: solr lucene solr4 solrcloud

以下是我的solr 4.7.2

中配置的示例文档和字段
brands {id, brand_name}
products {id, product_name, brand_id}

以下是索引的数据

BRANDS: {1, Apple}, {2, Samsung}, {3, HTC}

PRODUCTS: {10, iPhone, 1}, {11, iPad, 1}, {12, Galaxy S3, 2}, {13, Galaxy Note, 2}, {14, Desire, 3}

我想用brand_name获取所有产品是“Samsung”或product_name是“Desire”

brand_name:Samsung OR {!join from=brand_id to=id} product_name:Desire

但我得错误说

ERROR [SolrDispatchFilter] null:java.lang.NullPointerException: while trying to invoke the method org.apache.lucene.search.Query.hashCode() of a null object loaded from field org.apache.solr.search.JoinQuery.q of an object loaded from local variable 'this'
        at org.apache.solr.search.JoinQuery.hashCode(JoinQParserPlugin.java:594)
        at org.apache.lucene.search.BooleanClause.hashCode(BooleanClause.java:99)
        at java.util.AbstractList.hashCode(AbstractList.java:541)
        at org.apache.lucene.search.BooleanQuery.hashCode(BooleanQuery.java:520)
        at org.apache.solr.search.QueryResultKey.<init>(QueryResultKey.java:47)
        at org.apache.solr.search.SolrIndexSearcher.getDocListC(SolrIndexSearcher.java:1305)
        at org.apache.solr.search.SolrIndexSearcher.search(SolrIndexSearcher.java:476)
        at org.apache.solr.handler.component.QueryComponent.process(QueryComponent.java:461)
        at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:217)
        at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135)
        at org.apache.solr.core.SolrCore.execute(SolrCore.java:1916)
        at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:768)
        at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:415)
        at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:205)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        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:230)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:173)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:812)

使用OR和连接查询结果的正确方法是什么?我还想使用OR对多个联接结果进行分组。

跟查询

之类的东西

(field1:value1 OR field2:value2 OR field3:value3 OR {!join from = some_id to = some_other_id} field4:value4 OR {!join from = some_field_is to = some_other_field_id} field5:value5) AND field7:value7 AND datefield1:{* TO 2015-11-30T14:28:11Z}和datefield2:{2015-11-30T14:28:11Z TO *}

请建议是否有其他方法可以做到这一点。

1 个答案:

答案 0 :(得分:0)

这可以使用查询参数来完成。

(brand_name:Samsung OR {!join from=brand_id to=id v=$subquery})
&subquery=product_name:Desire