Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLR sorting based on date : storing date as toISOString(), whereas toUTCString fails

SOLR sorting based on date : storing date as toISOString(), whereas toUTCString fails

Problem

During storing date field into Solr, I convert Date() to toISOString() and it accepts. I tried storing using toUTCString, but it fails.

Now while searching, I am sorting based on date, I do get result, but these are not sorted in an descending order, rather I get it in mixed order.

I tried specifying a range, using [NOW-1YEAR/DAY TO NOW/DAY+1DAY], but the result is still the same. First I get 6 days old document, then 30min old doc and then 2 months old doc.

what should be the right approach ?

EDIT: Here is the date field that i added in schema.xml

   

and here are the parameters, I am sending during each search,

query = "*:*";
var options = {
            fq: '{!geofilt}',
            sfield: 'location',
            pt: latitude+','+longitude,
            d: 10,
            sort: ["message_date desc", "geodist() asc"],
            start: 0,
            rows: 10
        }

solrclient.query(query, options, function(err, solrRes){
....
});

This is javascript in the server side, node.js code.

Problem courtesy of: user644745

Solution

The above code is fine and it is working. Problem was, after retrieving the result from SOLR, I do a finer search in my database to get more details and that was not sorted. So sorted the result from Mongodb after retrieving the result from SOLR and that worked.

Using nodejs and the solr module is, https://github.com/gsf/node-solr

Solution courtesy of: user644745

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

SOLR sorting based on date : storing date as toISOString(), whereas toUTCString fails

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×