You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Santosh Kumar S <sa...@infinite.com> on 2019/07/10 13:22:07 UTC

Sorting based on Date and Name combination in Solr 6.2

Hi,
We have a scenario where we need to sort on Date and Name combination. We
have a Date field of type DateTime and a Name field.

When we try sorting it, then the records are getting sorted based on
Timestamp, but we need to sort only on date part keeping timestamp part
aside.

Here is an example : We need to sort the below 4 values :
2019-07-02 11:12:13Z SANTOSH
2019-07-02 12:12:13Z BALA
2019-07-02 13:13:13Z ANAND
2019-07-02 14:15:13Z CHANDAR

Expected Result is as follows :: 
2019-07-02 12:12:13Z ANAND
2019-07-02 13:13:13Z BALA
2019-07-02 14:15:13Z CHANDAR
2019-07-02 11:12:13Z SANTOSH

Here we would like the sort to consider only the date part of the field and
then use the name field. 
In this way, documents for different dates will appear sorted first by date
(without time) and then by name.

Below are the queries I have on this :
1. How can we achieve the above said scenario (explained in example above)
in Solr 6.2

Any solutions are highly appreciated.

Thank you in advance.








--
Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html

Re: Sorting based on Date and Name combination in Solr 6.2

Posted by Santosh Kumar S <sa...@infinite.com>.
Thank you Shawn for your prompt response. 
However we have that option open of having a separate date only field or a 
separate field with date along with default Timestamp like you mentioned 
(00:00:00.000). But this change shall need a full-import or full crawl, as 
we lot many data, we looking out at any other probable solution. 

Thank you once again and I appreciated your reply, I will definitely 
consider your solution. 



Shawn Heisey-2 wrote
> On 7/10/2019 7:22 AM, Santosh Kumar S wrote:
>> When we try sorting it, then the records are getting sorted based on
>> Timestamp, but we need to sort only on date part keeping timestamp part
>> aside.
> 
> That is how sorting on a field that has a timestamp is going to work. 
> It will always use the whole field.
> 
>> Here we would like the sort to consider only the date part of the field
>> and
>> then use the name field.
>> In this way, documents for different dates will appear sorted first by
>> date
>> (without time) and then by name.
> 
> If you want to only sort by date without the time, you will need a field 
> into which you index date only, either without the timestamp or with a 
> common timestamp (probably 00:00:00.000).  If going with date only, it's 
> probably better to use a string field than a date field.  It's up to you 
> whether you change the existing date field and update your indexing 
> software, or add a new one and have your indexing program copy the date 
> from the date field to a text field.
> 
> I do not know whether the ParseDateFieldUpdateProcessorFactory could be 
> used to handle this on the Solr side with a copyField:
> 
> https://lucene.apache.org/solr/7_2_0//solr-core/org/apache/solr/update/processor/ParseDateFieldUpdateProcessorFactory.html
> 
> Once you have the correct date only field, you would have to simply use 
> a parameter like this:
> 
> sort=date_only asc, name asc
> 
> Thanks,
> Shawn





--
Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html

Re: Sorting based on Date and Name combination in Solr 6.2

Posted by Santosh Kumar S <sa...@infinite.com>.
Thank you Shawn for your prompt response.
However we have that option open of having a separate date only field or a
separate field with date along with default Timestamp like you mentioned
(00:00:00.000). But this change shall need a full-import or full crawl, as
we lot many data, we looking out at any other probable solution.

Thank you once again and I appreciated your reply, I will definitely
consider your solution. 



--
Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html

Re: Sorting based on Date and Name combination in Solr 6.2

Posted by Shawn Heisey <ap...@elyograg.org>.
On 7/10/2019 7:22 AM, Santosh Kumar S wrote:
> When we try sorting it, then the records are getting sorted based on
> Timestamp, but we need to sort only on date part keeping timestamp part
> aside.

That is how sorting on a field that has a timestamp is going to work. 
It will always use the whole field.

> Here we would like the sort to consider only the date part of the field and
> then use the name field.
> In this way, documents for different dates will appear sorted first by date
> (without time) and then by name.

If you want to only sort by date without the time, you will need a field 
into which you index date only, either without the timestamp or with a 
common timestamp (probably 00:00:00.000).  If going with date only, it's 
probably better to use a string field than a date field.  It's up to you 
whether you change the existing date field and update your indexing 
software, or add a new one and have your indexing program copy the date 
from the date field to a text field.

I do not know whether the ParseDateFieldUpdateProcessorFactory could be 
used to handle this on the Solr side with a copyField:

https://lucene.apache.org/solr/7_2_0//solr-core/org/apache/solr/update/processor/ParseDateFieldUpdateProcessorFactory.html

Once you have the correct date only field, you would have to simply use 
a parameter like this:

sort=date_only asc, name asc

Thanks,
Shawn