Solr按功能查询的值排序不起作用 [英] Solr sort by the value of function query does not work

查看:112
本文介绍了Solr按功能查询的值排序不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一项功能,该功能依赖于对函数查询的值进行排序.

I'm working on a feature which relies on sorting the value of function query.

功能查询如下:

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类型的动态字段)存在,则排序基于字段的值,否则排序基于的值主题"也是文本字段(但它不是动态字段)

So basically what I'm doing is if the field "f1_t" (which is a dynamic field of type TextField) exists then the sorting is based on the value of the field else the sorting is based on the value of "theme" which is also a TextField (but it is not a dynamic field)

但是当我运行它时,它失败,并带有以下异常. 我用整数值尝试了"if"函数,它可以正常工作. 我只是想知道您是否可以帮助我弄清楚为什么上述函数查询失败?我该如何工作?

But when I run this it fails with the below exception. I tried the "if" function with integer values and it works fine. I was just wondering if you could help me figure out why the above function query fails? How can I get this working?

我正在使用的Solr版本是4.6.1

Solr version I'm using is 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 

推荐答案

我正在查看IfFunction $ 1.doubleVal(IfFunction.java:83)行,我认为这种情况与函数查询限制有关.可以在函数查询Wiki 中看到的那样,它可以对数字字段进行操作. :

I'm looking at the IfFunction$1.doubleVal(IfFunction.java:83) line and I think that the case is about Function Query restriction. It could operate on numeric fields as one can see in the Function Query wiki:

函数查询使您可以使用 一个或多个数字字段的实际值.

Function queries enable you to generate a relevancy score using the actual value of one or more numeric fields.

由于您已经知道要使用的字段,因此可以在索引时解决此特定问题.换句话说,创建代理排序字段,该字段将取值:

Since you know the fields you are going to use in advance you could solve this particular problem at index-time. In other words create surrogate sorting field, which will take value:

    如果f1_t字段存在,则
  • 来自user_h1_t字段
  • 否则来自theme字段
  • from user_h1_t field if f1_t field exists
  • from theme field otherwise

这篇关于Solr按功能查询的值排序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆