tags:

views:

19

answers:

2

hi all

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?

+2  A: 

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.

Mauricio Scheffer
A: 

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"/>`
Paige Cook