Salt combining date fields when sorting

We have documents indexed with the date d1 for some documents and d2 for others, and we want to sort them by both of them, depending on which one is available.

 sort=d1 desc, d2 desc 

sorts a document with d1 separately for a document using d2 , for example:

 d1: 2014-03-12 d1: 2010-03-12 d2: 2013-03-12 d2: 2011-03-12 

We want everything to be sorted as follows:

 d1: 2014-03-12 d2: 2013-03-12 d2: 2011-03-12 d1: 2010-03-12 

Re-examination of all documents with a new common field, unfortunately, is not an option.

+6
source share
6 answers

As far as I know, you can use solr function queries. For this kind, it's something like this

sort = if ((abs (ms (d1, d2))> 0), d1, d2) desc

I have not tested it yet, but here is a useful link that will help you solve your problem.

https://wiki.apache.org/solr/FunctionQuery
Sort result by date

+1
source

Abdul's approach to using a function is the right approach. But Abdul's solution does not work for me.

I have successfully tested this.

Just add this parameter to the query:

 sort=max(d1,d2) desc 
+1
source

Perhaps you can add copyField from d1 and d2 to dAll and then sort by dAll?

You can check the copy information: https://cwiki.apache.org/confluence/display/solr/Copying+Fields

0
source

As shown in this discussion , you can update your data with ConcatFieldUpdateProcessorFactory by trying something like:

 <processor class="com.test.solr.update.CustomConcatFieldUpdateprocessorFactory"> <str name="field">d1</str> <str name="field">d2</str> <str name="dest">date</str> <str name="delimiter"></str> </processor> 

After that, you can try sorting by the date of your field.

0
source

Two proposals, one of which has already been proposed:

(1) Use copyField .

 <field name="d" type="date" indexed="true" stored="true" multiValued="false"/> <copyField source="d1" dest="d" /> <copyField source="d2" dest="d" /> 

Even if the d1 and d2 fields are important, you can include them in your query, but just sort in the combined d field.

(2) Depending on the type of data source, you can modify the query in the data-config.xml file to combine these two fields into one. In our environment, we use Solr to index data from a MySQL instance. There are many times when data from different databases is combined into Solr. This leads to a similar problem when we need to normalize the data coming from different databases. In these situations, we often use constructs such as CASE or IFNULL in our queries. I can get more details if applicable to your situation.

0
source

I had a problem very similar to yours. In my case, all documents had the fields "d1" and "d2", and they all had the value "d1". The value "d2" is used to overwrite the value of "d1".

My solution for this:

 sort=map(ms(d2),0,0,ms(d1)) desc 

map(ms(d2),0,0,ms(d1)) will return the time stamp "d2" if it is not empty; if so, the label "d1" is used instead

Hope this helps someone.

0
source

All Articles