【发布时间】:2017-03-04 03:47:38
【问题描述】:
我正在开发一个依赖于对函数查询值进行排序的功能。
功能查询如下:
http://localhost:8983/solr/collection/select?q=*:*&sort=if(exists(f1_t), f1_t, theme)+ASC&wt=json&indent=true
排序函数为“if(exists(f1_t), f1_t, theme) ASC”
所以基本上我正在做的是如果字段“f1_t”(这是一个 TextField 类型的动态字段)存在,那么排序基于字段的值,否则排序基于“主题”也是一个 TextField(但它不是动态字段)
但是当我运行它时它会失败并出现以下异常。 我尝试了带有整数值的“if”函数,它工作正常。 我只是想知道您是否可以帮我弄清楚上述函数查询失败的原因?我怎样才能让它工作?
我使用的 Solr 版本是 4.6.1
"trace": "java.lang.UnsupportedOperationException\n\tat
org.apache.lucene.queries.function.FunctionValues.doubleVal(FunctionValues.java:47)\n\tat
org.apache.lucene.queries.function.valuesource.IfFunction$1.doubleVal(IfFunction.java:83)\n\tat
org.apache.lucene.queries.function.ValueSource$ValueSourceComparator.copy(ValueSource.java:152)\n\tat
org.apache.lucene.search.TopFieldCollector$OneComparatorNonScoringCollector.collect(TopFieldCollector.java:86)\n\tat
org.apache.lucene.search.Scorer.score(Scorer.java:65)\n\tat
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:621)\n\tat
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:297)\n\tat
org.apache.solr.search.SolrIndexSearcher.getDocListNC(SolrIndexSearcher.java:1529)\n\tat
org.apache.solr.search.SolrIndexSearcher.getDocListC(SolrIndexSearcher.java:1395)\n\tat
org.apache.solr.search.SolrIndexSearcher.search(SolrIndexSearcher.java:474)\n\tat
org.apache.solr.handler.component.QueryComponent.process(QueryComponent.java:438)\n\tat
org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:208)\n\tat
org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135)\n\tat org.apache.solr.core.SolrCore.execute(SolrCore.java:1859)\n\tat
org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:723)\n\tat
org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:419)\n\tat
org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:203)\n\tat
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)\n\tat
org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)\n\tat
org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)\n\tat
org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)\n\tat
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)\n\tat
org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)\n\tat
org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)\n\tat
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)\n\tat
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)\n\tat
org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)\n\tat
org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)\n\tat
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)\n\tat org.eclipse.jetty.server.Server.handle(Server.java:368)\n\tat
org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)\n\tat
org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)\n\tat
org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:942)\n\tat
org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1004)\n\tat
org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:640)\n\tat
org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)\n\tat
org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)\n\tat
org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)\n\tat
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)\n\tat
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)\n\tat java.lang.Thread.run(Thread.java:662)\n",
"code": 500
【问题讨论】:
-
按 TextFields 排序将无法按预期工作,除非该字段是关键字标记的。如果可能,使用 StrField 进行排序。
-
我可以将它们更改为 StrField,但是否可以使用 StrField 实现这种排序功能?我尝试了 StrField 并得到了同样的异常
-
您的问题与this SO 问题有关。目前在 lucene 中构建的排序方式不允许使用除双精度之外的任何其他内容进行搜索。这就是为什么排序函数
if(exists(firstname), firstname, lastname) asc不能工作,solr在FunctionValues#doubleVal(int)方法返回UnsupportedOperationException的原因。
标签: solr lucene solrj solr4 solrcloud