如何使用 SOLR url 对结果集进行排序?
How do I sort result set using a SOLR url?
我有以下 URL:
http://webaddress:8994/solr/crossmedia/select?q=MEM_ED_NUMBER:136250%20AND%20CM_TYPE:WEB_MOBILE&rows=0&wt=json&indent=true&json.facet={Level1:{type:terms,field:ENTRY_DATE,limit:100,facet:{Level2: {type:terms,field:NAME_URL,limit:100,facet:{sum:"sum(PAGE_IMPRESSIONS)",sum2:"sum(PAGE_IMPRESSIONS)"}}}}}
产生以下结果:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"MEM_ED_NUMBER:136250 AND CM_TYPE:WEB_MOBILE",
"json.facet":"{Level1:{type:terms,field:ENTRY_DATE,limit:100,facet:{Level2:{type:terms,field:NAME_URL,limit:100,facet:{sum:\"sum(PAGE_IMPRESSIONS)\",sum2:\"sum(PAGE_IMPRESSIONS)\"}}}}}",
"indent":"true",
"rows":"0",
"wt":"json"}},
"response":{"numFound":32,"start":0,"docs":[]
},
"facets":{
"count":32,
"Level1":{
"buckets":[{
"val":"2015-01-01T00:00:01Z",
"count":2,
"Level2":{
"buckets":[{
"val":"www.newarkadvocate.com",
"count":2,
"sum":7118768.0,
"sum2":7118768.0}]}},
{
"val":"2015-02-01T00:00:01Z",
"count":2,
"Level2":{
"buckets":[{
"val":"www.newarkadvocate.com",
"count":2,
"sum":7458540.0,
"sum2":7458540.0}]}},
{
"val":"2015-03-01T00:00:01Z",
"count":2,
"Level2":{
"buckets":[{
"val":"www.newarkadvocate.com",
"count":2,
"sum":7737596.0,
"sum2":7737596.0}]}},
{
"val":"2015-04-01T00:00:01Z",
"count":2,
"Level2":{
"buckets":[{
"val":"www.newarkadvocate.com",
"count":2,
"sum":8968393.0,
我想做的是按 ENTRY_DATE 降序排列,但我没弄对。
我试过了
http://webaddress:8994/solr/crossmedia/select?q=MEM_ED_NUMBER:136250%20AND%20CM_TYPE:WEB_MOBILE&sort=ENTRY_DATE%20desc&rows=0&wt=json&indent=true&json.facet={Level1:{type:terms,field:ENTRY_DATE,limit:100,facet:{Level2:{type:terms,field:NAME_URL,limit:100,facet:{sum:"sum(PAGE_IMPRESSIONS)",sum2:"sum(PAGE_IMPRESSIONS)"}}}}}
这给了我相同的结果集,没有顺序变化。
我试过了
http://webaddress:8994/solr/crossmedia/select?q=MEM_ED_NUMBER:136250%20AND%20CM_TYPE:WEB_MOBILE&rows=0&wt=json&indent=true&json.facet={Level1:{type:terms,field:ENTRY_DATE,sort:"ENTRY_DATE%20desc",limit:100,facet:{Level2:{type:terms,field:NAME_URL,limit:100,facet:{sum:%22sum(PAGE_IMPRESSIONS)%22,sum2:%22sum(PAGE_IMPRESSIONS)%22}}}}}
这给我一个错误。
有人可以帮忙吗?
谢谢,
鲍勃
这是来自最新 URL 的带有固定大括号的错误消息。
{
"responseHeader":{
"status":500,
"QTime":0,
"params":{
"q":"MEM_ED_NUMBER:136250 AND CM_TYPE:WEB_MOBILE",
"json.facet":" {Level1: {sort: {ENTRY_DATE: desc}, type:terms, field:ENTRY_DATE, limit:100, facet:{Level2: {type:terms,field:NAME_URL,limit:100,facet: {sum:\"sum(PAGE_IMPRESSIONS)\",sum2:\"sum(PAGE_IMPRESSIONS)\"}}}}}",
"indent":"true",
"rows":"0",
"wt":"json"}},
"response":{"numFound":32,"start":0,"docs":[]
},
"error":{
"trace":"java.lang.NullPointerException\r\n\tat org.apache.solr.search.facet.FacetFieldProcessorNumeric.lessThan(FacetFieldProcessorNumeric.java:371)\r\n\tat org.apache.solr.search.facet.FacetFieldProcessorNumeric.lessThan(FacetFieldProcessorNumeric.java:367)\r\n\tat org.apache.lucene.util.PriorityQueue.upHeap(PriorityQueue.java:258)\r\n\tat org.apache.lucene.util.PriorityQueue.add(PriorityQueue.java:135)\r\n\tat org.apache.lucene.util.PriorityQueue.insertWithOverflow(PriorityQueue.java:151)\r\n\tat org.apache.solr.search.facet.FacetFieldProcessorNumeric.calcFacets(FacetFieldProcessorNumeric.java:397)\r\n\tat org.apache.solr.search.facet.FacetFieldProcessorNumeric.process(FacetFieldProcessorNumeric.java:151)\r\n\tat org.apache.solr.search.facet.FacetProcessor.processSubs(FacetRequest.java:267)\r\n\tat org.apache.solr.search.facet.FacetProcessor.fillBucket(FacetRequest.java:354)\r\n\tat org.apache.solr.search.facet.FacetQueryProcessor.process(FacetQuery.java:57)\r\n\tat org.apache.solr.search.facet.FacetModule.process(FacetModule.java:87)\r\n\tat org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:255)\r\n\tat org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:143)\r\n\tat org.apache.solr.core.SolrCore.execute(SolrCore.java:2064)\r\n\tat org.apache.solr.servlet.HttpSolrCall.execute(HttpSolrCall.java:654)\r\n\tat org.apache.solr.servlet.HttpSolrCall.call(HttpSolrCall.java:450)\r\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:227)\r\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:196)\r\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)\r\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)\r\n\tat org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)\r\n\tat org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)\r\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)\r\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)\r\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)\r\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\r\n\tat org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)\r\n\tat org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)\r\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)\r\n\tat org.eclipse.jetty.server.Server.handle(Server.java:497)\r\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)\r\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)\r\n\tat org.eclipse.jetty.io.AbstractConnection.run(AbstractConnection.java:540)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:555)\r\n\tat java.lang.Thread.run(Unknown Source)\r\n",
"code":500}}
这是我的 SOLR 请求:
http://webdev:8994/solr/crossmedia/select?q=MEM_ED_NUMBER:136250%20AND%20CM_TYPE:WEB_MOBILE&rows=0&wt=json&indent=true&json.facet=%20{Level1:%20{sort:%20{ENTRY_DATE:%20desc},%20type:terms,%20field:ENTRY_DATE,%20limit:100,%20facet:{Level2:%20{type:terms,field:NAME_URL,limit:100,facet:%20{sum:%22sum(PAGE_IMPRESSIONS)%22,sum2:%22sum(PAGE_IMPRESSIONS)%22}}}}}
试试这个:
http://webaddress:8994/solr/crossmedia/select?q=MEM_ED_NUMBER:136250%20AND%20CM_TYPE:WEB_MOBILE&rows=0&wt=json&indent=true&json.facet=
{Level1:
{sort: {ENTRY_DATE: desc},
type:terms,
field:ENTRY_DATE,
limit:100,
facet:{Level2:
{type:terms,field:NAME_URL,limit:100,facet:
{sum:%22sum(PAGE_IMPRESSIONS)%22,sum2:%22sum(PAGE_IMPRESSIONS)%22}}}}}
这是我最终使用的数据,以使其正常工作
http://webdev.auditedmedia.com:8994/solr/crossmedia/select?q=MEM_ED_NUMBER%3A136250+AND+CM_TYPE%3AWEB_MOBILE&rows=0&wt=json&indent=true&json.facet={%22Level1%22:{%22type%22:%22terms%22,%22field%22:%22ENTRY_DATE%22,%22limit%22:100,%22sort%22:{%22index%22:%22desc%22},%22facet%22:{%22Level2%22:{%22type%22:%22terms%22,%22field%22:%22NAME_URL%22,%22limit%22:100,%22facet%22:{%22sum%22:%22sum(PAGE_IMPRESSIONS)%22,%22sum2%22:%22sum(PAGE_IMPRESSIONS)%22}}}}}
排序是级别 1 的一部分,它使用索引而不是 Entry_Date
我有以下 URL:
http://webaddress:8994/solr/crossmedia/select?q=MEM_ED_NUMBER:136250%20AND%20CM_TYPE:WEB_MOBILE&rows=0&wt=json&indent=true&json.facet={Level1:{type:terms,field:ENTRY_DATE,limit:100,facet:{Level2: {type:terms,field:NAME_URL,limit:100,facet:{sum:"sum(PAGE_IMPRESSIONS)",sum2:"sum(PAGE_IMPRESSIONS)"}}}}}
产生以下结果:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"MEM_ED_NUMBER:136250 AND CM_TYPE:WEB_MOBILE",
"json.facet":"{Level1:{type:terms,field:ENTRY_DATE,limit:100,facet:{Level2:{type:terms,field:NAME_URL,limit:100,facet:{sum:\"sum(PAGE_IMPRESSIONS)\",sum2:\"sum(PAGE_IMPRESSIONS)\"}}}}}",
"indent":"true",
"rows":"0",
"wt":"json"}},
"response":{"numFound":32,"start":0,"docs":[]
},
"facets":{
"count":32,
"Level1":{
"buckets":[{
"val":"2015-01-01T00:00:01Z",
"count":2,
"Level2":{
"buckets":[{
"val":"www.newarkadvocate.com",
"count":2,
"sum":7118768.0,
"sum2":7118768.0}]}},
{
"val":"2015-02-01T00:00:01Z",
"count":2,
"Level2":{
"buckets":[{
"val":"www.newarkadvocate.com",
"count":2,
"sum":7458540.0,
"sum2":7458540.0}]}},
{
"val":"2015-03-01T00:00:01Z",
"count":2,
"Level2":{
"buckets":[{
"val":"www.newarkadvocate.com",
"count":2,
"sum":7737596.0,
"sum2":7737596.0}]}},
{
"val":"2015-04-01T00:00:01Z",
"count":2,
"Level2":{
"buckets":[{
"val":"www.newarkadvocate.com",
"count":2,
"sum":8968393.0,
我想做的是按 ENTRY_DATE 降序排列,但我没弄对。
我试过了
http://webaddress:8994/solr/crossmedia/select?q=MEM_ED_NUMBER:136250%20AND%20CM_TYPE:WEB_MOBILE&sort=ENTRY_DATE%20desc&rows=0&wt=json&indent=true&json.facet={Level1:{type:terms,field:ENTRY_DATE,limit:100,facet:{Level2:{type:terms,field:NAME_URL,limit:100,facet:{sum:"sum(PAGE_IMPRESSIONS)",sum2:"sum(PAGE_IMPRESSIONS)"}}}}}
这给了我相同的结果集,没有顺序变化。
我试过了
http://webaddress:8994/solr/crossmedia/select?q=MEM_ED_NUMBER:136250%20AND%20CM_TYPE:WEB_MOBILE&rows=0&wt=json&indent=true&json.facet={Level1:{type:terms,field:ENTRY_DATE,sort:"ENTRY_DATE%20desc",limit:100,facet:{Level2:{type:terms,field:NAME_URL,limit:100,facet:{sum:%22sum(PAGE_IMPRESSIONS)%22,sum2:%22sum(PAGE_IMPRESSIONS)%22}}}}}
这给我一个错误。
有人可以帮忙吗?
谢谢, 鲍勃
这是来自最新 URL 的带有固定大括号的错误消息。
{
"responseHeader":{
"status":500,
"QTime":0,
"params":{
"q":"MEM_ED_NUMBER:136250 AND CM_TYPE:WEB_MOBILE",
"json.facet":" {Level1: {sort: {ENTRY_DATE: desc}, type:terms, field:ENTRY_DATE, limit:100, facet:{Level2: {type:terms,field:NAME_URL,limit:100,facet: {sum:\"sum(PAGE_IMPRESSIONS)\",sum2:\"sum(PAGE_IMPRESSIONS)\"}}}}}",
"indent":"true",
"rows":"0",
"wt":"json"}},
"response":{"numFound":32,"start":0,"docs":[]
},
"error":{
"trace":"java.lang.NullPointerException\r\n\tat org.apache.solr.search.facet.FacetFieldProcessorNumeric.lessThan(FacetFieldProcessorNumeric.java:371)\r\n\tat org.apache.solr.search.facet.FacetFieldProcessorNumeric.lessThan(FacetFieldProcessorNumeric.java:367)\r\n\tat org.apache.lucene.util.PriorityQueue.upHeap(PriorityQueue.java:258)\r\n\tat org.apache.lucene.util.PriorityQueue.add(PriorityQueue.java:135)\r\n\tat org.apache.lucene.util.PriorityQueue.insertWithOverflow(PriorityQueue.java:151)\r\n\tat org.apache.solr.search.facet.FacetFieldProcessorNumeric.calcFacets(FacetFieldProcessorNumeric.java:397)\r\n\tat org.apache.solr.search.facet.FacetFieldProcessorNumeric.process(FacetFieldProcessorNumeric.java:151)\r\n\tat org.apache.solr.search.facet.FacetProcessor.processSubs(FacetRequest.java:267)\r\n\tat org.apache.solr.search.facet.FacetProcessor.fillBucket(FacetRequest.java:354)\r\n\tat org.apache.solr.search.facet.FacetQueryProcessor.process(FacetQuery.java:57)\r\n\tat org.apache.solr.search.facet.FacetModule.process(FacetModule.java:87)\r\n\tat org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:255)\r\n\tat org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:143)\r\n\tat org.apache.solr.core.SolrCore.execute(SolrCore.java:2064)\r\n\tat org.apache.solr.servlet.HttpSolrCall.execute(HttpSolrCall.java:654)\r\n\tat org.apache.solr.servlet.HttpSolrCall.call(HttpSolrCall.java:450)\r\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:227)\r\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:196)\r\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)\r\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)\r\n\tat org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)\r\n\tat org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)\r\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)\r\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)\r\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)\r\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\r\n\tat org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)\r\n\tat org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)\r\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)\r\n\tat org.eclipse.jetty.server.Server.handle(Server.java:497)\r\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)\r\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)\r\n\tat org.eclipse.jetty.io.AbstractConnection.run(AbstractConnection.java:540)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:555)\r\n\tat java.lang.Thread.run(Unknown Source)\r\n",
"code":500}}
这是我的 SOLR 请求:
http://webdev:8994/solr/crossmedia/select?q=MEM_ED_NUMBER:136250%20AND%20CM_TYPE:WEB_MOBILE&rows=0&wt=json&indent=true&json.facet=%20{Level1:%20{sort:%20{ENTRY_DATE:%20desc},%20type:terms,%20field:ENTRY_DATE,%20limit:100,%20facet:{Level2:%20{type:terms,field:NAME_URL,limit:100,facet:%20{sum:%22sum(PAGE_IMPRESSIONS)%22,sum2:%22sum(PAGE_IMPRESSIONS)%22}}}}}
试试这个:
http://webaddress:8994/solr/crossmedia/select?q=MEM_ED_NUMBER:136250%20AND%20CM_TYPE:WEB_MOBILE&rows=0&wt=json&indent=true&json.facet=
{Level1:
{sort: {ENTRY_DATE: desc},
type:terms,
field:ENTRY_DATE,
limit:100,
facet:{Level2:
{type:terms,field:NAME_URL,limit:100,facet:
{sum:%22sum(PAGE_IMPRESSIONS)%22,sum2:%22sum(PAGE_IMPRESSIONS)%22}}}}}
这是我最终使用的数据,以使其正常工作
http://webdev.auditedmedia.com:8994/solr/crossmedia/select?q=MEM_ED_NUMBER%3A136250+AND+CM_TYPE%3AWEB_MOBILE&rows=0&wt=json&indent=true&json.facet={%22Level1%22:{%22type%22:%22terms%22,%22field%22:%22ENTRY_DATE%22,%22limit%22:100,%22sort%22:{%22index%22:%22desc%22},%22facet%22:{%22Level2%22:{%22type%22:%22terms%22,%22field%22:%22NAME_URL%22,%22limit%22:100,%22facet%22:{%22sum%22:%22sum(PAGE_IMPRESSIONS)%22,%22sum2%22:%22sum(PAGE_IMPRESSIONS)%22}}}}}
排序是级别 1 的一部分,它使用索引而不是 Entry_Date