0

Assume I have field and value like

Field : value
sku : xxx
Seller : true
Name : "Elux"

query will be like

sku:"xxx"

within this result I need to sort the products with Name (Elux) in the top with seller (true) top and within that I need the products name should be sorted in alphabetical order same goes for seller (false) and Name other than Elux in the bottom. Is this possible with solr?

pradeep murugan
  • 531
  • 1
  • 9
  • 18

1 Answers1

1

You can use the same strategy as shown in this answer by Alexandre, but you'll have to adapt it to your need. Something like:

&sort=query(Name:Elux, 0) desc, query(seller:true, 0) desc, Name asc

.. should work. Not sure about the performance from those two query calls, though.

Update:

You'll have to use placeholders as Alexandre describes in his answer:

sort=query($manu_sort,0) desc, query($seller_sort,0) desc, ManufacturerName asc
&manu_sort=ManufacturerName:Champ
&seller_sort=BestSeller:true
MatsLindh
  • 49,529
  • 4
  • 53
  • 84
  • Im getting this erro when i use "&sort=query(Name:Elux, 0) desc" "Can't determine a Sort Order (asc or desc) in sort spec 'query(Name:Elux, 0) desc', pos=16" – pradeep murugan Jun 20 '19 at 09:03
  • You'll probably have to use "" around the query, or use the method described in the linked answer with placeholders. Try it and I'll update the answer if it works or remove it if not. – MatsLindh Jun 20 '19 at 09:14
  • How does this query work "query(Name:Elux, 0) desc" can you explain It dosent seems to be working for me. Thanks for your time – pradeep murugan Jun 21 '19 at 08:00
  • Im getting a error like "sort param could not be parsed as a query," – pradeep murugan Jun 21 '19 at 08:05
  • As I mentioned in my previous comment, try to use `"` around the query, or use placeholders as shown in the linked answer by Alexandre. – MatsLindh Jun 21 '19 at 08:17
  • Add five example documents in JSON to your question and the expected output and I'll dig further in a couple of hours – MatsLindh Jun 21 '19 at 08:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/195324/discussion-between-pradeep-murugan-and-matslindh). – pradeep murugan Jun 21 '19 at 08:34
  • Thankyou and final thing how to make this "ManufacturerName:Champ" case insensitive ? – pradeep murugan Jun 21 '19 at 09:45
  • You add a LowercaseFilter to your processing chain for that field. – MatsLindh Jun 21 '19 at 10:59
  • How do I change this query to dismax type? – pradeep murugan Jun 22 '19 at 03:32
  • The sort query or the general query? `defType=edismax` would change the type of the query itself. – MatsLindh Jun 22 '19 at 04:38
  • Thanks a lot. Yes, I need to implement this sort in dismax query format. – pradeep murugan Jun 22 '19 at 04:42
  • I used this query "q=*:*&sort=query({!dismax v=$manu_sort},0) desc &manu_sort=ManufacturerName:"Service Champ" Im getting error "Can't determine a Sort Order (asc or desc) in sort spec 'query({!dismax v=$manu_sort},0) desc ', pos=14" – pradeep murugan Jun 22 '19 at 16:39
  • can you give me a sample query? I dono what you mean by "Try inside manu_sort" – pradeep murugan Jun 23 '19 at 03:26
  • `manu_sort={!dismax}ManufacturerName:"Service Champ" or `manu_sort={!dismax v=ManufacturerName:"Service Champ"}`. You should also be able to use `edismax` - the more modern version. dismax is usually used without a field name and with the `qf` parameter instead. – MatsLindh Jun 23 '19 at 08:23