Sergei Vatshekin
Sergei Vatshekin

Reputation: 61

Apache Solr: sort by one of fields (with condition)

I want to add sorting by "field1" if it's exists in document, and by "field2" if not. Help me please with query syntax.

Upvotes: 2

Views: 2614

Answers (1)

marius_neo
marius_neo

Reputation: 1595

As already pointed in this SO question

try to use something like this for int fields :

sort=min(def(A_160018,9000000),def(A_chandigarh1,9000000))

For string fields the option would be to use in the core/collection an extra field containing the concatenation of the fields - e.g. fullname: lastname + ' ' + firstname written explicitly in the document when it is created. Then you can still do sort=fullname asc

Upvotes: 2

Related Questions