Ahsan Iqbal
Ahsan Iqbal

Reputation: 1432

Question related to Solr DateField?

I have a question related to sorting of date field i have Date field that is indexed like a string and look like "5/2/2008 4:33:30 PM" i want to do sorting on this field on the basis of date, time does not matters. any suggestion how i could ignore the time part from this field and just sort on the date?

Upvotes: 0

Views: 844

Answers (2)

Paige Cook
Paige Cook

Reputation: 22555

I agree with Mauricio, us a separate field. But I would also recommend keeping in mind the pdate field type that is explained in the example Solr schema (see below). Especially if you will have missing date data on documents and will need to sort those first/last.

 `Note:
  These should only be used for compatibility with existing indexes (created with older Solr versions)
  or if "sortMissingFirst" or "sortMissingLast" functionality is needed. Use Trie based fields instead.

  Plain numeric field types that store and index the text
  value verbatim (and hence don't support range queries, since the
  lexicographic ordering isn't equal to the numeric ordering) 

<fieldType name="pdate" class="solr.DateField" sortMissingLast="true" omitNorms="true"/>`

Upvotes: 0

Mauricio Scheffer
Mauricio Scheffer

Reputation: 99720

I would create another field specifically for this purpose, when you populate it you just strip the time out of your data source and then sort on this field.

Upvotes: 3

Related Questions