Solr facet on value changed field

How I use facet in changed values in the search?

To distinguish if the logged in user is the manufacturer of the product i changed values in search:

http://localhost:8983/solr/techproducts/select?facet.field=opt_s&facet=on&fl=name,manu,manu_id_s,features,opt_s:if(termfreq(manu_id_s,'corsair'),'mine','notmine')&q=memory

{
  "responseHeader":{
    "status":0,
    "QTime":0,
    "params":{
      "q":"memory",
      "facet.field":"opt_s",
      "fl":"name,manu,manu_id_s,features,opt_s:if(termfreq(manu_id_s,'corsair'),'mine','notmine')",
      "facet":"on"}},
  "response":{"numFound":5,"start":0,"docs":[
      {
        "name":"CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail",
        "manu":"Corsair Microsystems Inc.",
        "manu_id_s":"corsair",
        "opt_s":"mine"},
      {
        "name":"A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM",
        "manu":"A-DATA Technology Inc.",
        "manu_id_s":"corsair",
        "features":["CAS latency 3,   2.7v"],
        "opt_s":"mine"},
      {
        "name":"CORSAIR  XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail",
        "manu":"Corsair Microsystems Inc.",
        "manu_id_s":"corsair",
        "features":["CAS latency 2,  2-3-3-6 timing, 2.75v, unbuffered, heat-spreader"],
        "opt_s":"mine"},
      {
        "name":"Canon PIXMA MP500 All-In-One Photo Printer",
        "manu":"Canon Inc.",
        "manu_id_s":"canon",
        "features":["Multifunction ink-jet color photo printer",
          "Flatbed scanner, optical scan resolution of 1,200 x 2,400 dpi",
          "2.5\" color LCD preview screen",
          "Duplex Copying",
          "Printing speed up to 29ppm black, 19ppm color",
          "Hi-Speed USB",
          "memory card: CompactFlash, Micro Drive, SmartMedia, Memory Stick, Memory Stick Pro, SD Card, and MultiMediaCard"],
        "opt_s":"notmine"},
      {
        "name":"ASUS Extreme N7800GTX/2DHTV (256 MB)",
        "manu":"ASUS Computer Inc.",
        "manu_id_s":"asus",
        "features":["NVIDIA GeForce 7800 GTX GPU/VPU clocked at 486MHz",
          "256MB GDDR3 Memory clocked at 1.35GHz",
          "PCI Express x16",
          "Dual DVI connectors, HDTV out, video input",
          "OpenGL 2.0, DirectX 9.0"],
        "opt_s":"notmine"}]
  },
  "facet_counts":{
    "facet_queries":{},
    "facet_fields":{
      "opt_s":[]},
    "facet_ranges":{},
    "facet_intervals":{},
    "facet_heatmaps":{}}}

Thx in advance!

1 answer

  • answered 2018-11-07 18:49 MatsLindh

    Use facet queries - one to count the documents that belong to the correct set, one to count the other:

    facet.query=manu_id_s:corsair&facet.query=*:* -manu_id_s:corsair