user3386503
user3386503

Reputation: 1

apache solr search sorting by field value

I'm using Apache solr search and having problem in sorting by field value.

Can any one resolve this issue?

i.e Suppose we have a field named 'function_area' and value may be 1,2,3,4.

But I want that record containing function_area=2 should come on top and the rest records should come in ascending order by function_area.

Records in order

Record 1 => function_area=2

Record 2 => function_area=1

Record 2 => function_area=3

Record 2 => function_area=4

Upvotes: 0

Views: 457

Answers (1)

Shishir Kumar
Shishir Kumar

Reputation: 8201

You can make use of sort parameters which are present as CommonQueryParameters in Solr. Moreover, FunctionQuery since Solr 3.1 can also be explored here.

The exists function may be used in order to get the results with specific field value ordered first:

http://localhost:8983/solr/collection1/select=q=*:*&sort=exists(query({!v='function_area:2'})) DESC

Upvotes: 1

Related Questions