Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

Sorting always results in NullPointerException #248

Open
rvanzon opened this issue Apr 18, 2017 · 5 comments
Open

Sorting always results in NullPointerException #248

rvanzon opened this issue Apr 18, 2017 · 5 comments

Comments

@rvanzon
Copy link

rvanzon commented Apr 18, 2017

Hi,

I am trying to sort the results of my query, but it always results in a { code: 500 } in the browser, couchdb-lucene outputs:

java.lang.NullPointerException
	at org.apache.lucene.search.SortField.getComparator(SortField.java:340)
	at org.apache.lucene.search.FieldValueHitQueue.<init>(FieldValueHitQueue.java:142)
	at org.apache.lucene.search.FieldValueHitQueue.<init>(FieldValueHitQueue.java:32)
	at org.apache.lucene.search.FieldValueHitQueue$OneComparatorFieldValueHitQueue.<init>(FieldValueHitQueue.java:63)
	at org.apache.lucene.search.FieldValueHitQueue.create(FieldValueHitQueue.java:166)
	at org.apache.lucene.search.TopFieldCollector.create(TopFieldCollector.java:492)
	at org.apache.lucene.search.IndexSearcher$4.newCollector(IndexSearcher.java:562)
	at org.apache.lucene.search.IndexSearcher$4.newCollector(IndexSearcher.java:557)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:591)
	at org.apache.lucene.search.IndexSearcher.searchAfter(IndexSearcher.java:577)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:504)
	at com.github.rnewson.couchdb.lucene.DatabaseIndexer.search(DatabaseIndexer.java:533)
	at com.github.rnewson.couchdb.lucene.LuceneServlet.doGetInternal(LuceneServlet.java:193)
	at com.github.rnewson.couchdb.lucene.LuceneServlet.doGet(LuceneServlet.java:171)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:845)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:459)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1176)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1106)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
	at org.eclipse.jetty.server.Server.handle(Server.java:524)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:319)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:253)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
	at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)
	at java.lang.Thread.run(Thread.java:745)

I tried several indexes, from:

"by_body": {
      "index": "function(doc) { var ret=new Document(); ret.add(doc.body); return ret }"
}

to

"by_text": {
     "index": "function(doc) { var ret=new Document(); 
        ret.add(doc.title, { \"field\": \"text\" }); ret.add(doc.body, { \"field\": \"text\" }); 
        ret.add(doc.publishAt, { \"field\": \"date\", \"type\": \"date\" });  
        return ret }"
},

I am calling the latter with:

http://localhost:5986/_fti/local/nwst-cms-greenkeeper-dev/_design/search/by_text?q=text:keyword&include_docs=true&sort=date

any ideas?

@rvanzon
Copy link
Author

rvanzon commented Apr 26, 2017

Nobody has problems with sorting? Kinda stuck here..

@rnewson
Copy link
Owner

rnewson commented Apr 26, 2017

You'll need to sort on a numeric field or an untokenized field, that's a Lucene restriction.

@rvanzon
Copy link
Author

rvanzon commented Apr 26, 2017

Ok, like we were talking about via Slack. Adding <string> to the query fixes it.

...search/by_text?q=text:keyword&include_docs=true&sort=date<string>

As you mentioned, a fix is underway.

@carrotalan
Copy link

+1 for this. Trying to sort via Javascript date object (e.g. createdAt: 2018-02-01T14:26:47.668Z) and cannot get it to work. Either Error 500 without the bit, or no results with the string bit. Followed exactly the same process as @rvanzon

@rnewson
Copy link
Owner

rnewson commented Mar 15, 2018

@carrotalan could you open a new issue with details please?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants