Reputation: 1
I am trying to implement a selection of multiple facets of the same category, so when the user selects option A1 and option A2 of category A and option B1 of category B - the results he should get are for (A1 OR A2) AND (B1).
I am working with solr and blacklight (v5.3.0).
I tried to use blacklight_advanced_search (v5.1.2) gem and changed the view for the advanced. I succeed to implement the view for that, but still the results that solr returns are A1 AND A2 AND B1.
How can I make solr use OR between the facets of the same category instead of AND?
thanks
Upvotes: 0
Views: 306
Reputation: 1872
Solr 5.4.0; Ruby:2.2.4; Rails:4.2.6 here category A=color and B=productBrand check how your filter query fq For me, initial
fq = [{"!term f=color}Blue","{!term f=color}Black","{!term f=productBrand}Apple"]
But after refering Blacklight examples from https://github.com/sul-dlss/revs their filter query also looks similar
"fq"=>["((: -visibility_isi:[* TO *]) OR visibility_isi:1)", "{!raw f=format_ssim}black-and-white negatives", "{!raw f=marque_ssim}Ford", "{!raw f=marque_ssim}Chevy"] which is working
but its not working for me , and blacklight_advanced_search --version problem
So, i changed the request.rb file -- change action append_filter_query according to the requirements Also edit catalog.rb
config.add_facet_field 'productBrand', label: 'Brand' , :tag => 'some-tag', :ex => 'some-tag'
config.add_facet_field 'color', label: 'Color' , :tag => 'color', :ex => 'color'
After editing the files i got this fq which is working as i want it to be (similar to ur requirement) selects Blue or Black and Apple
fq=["{!tag=color}color:(Blue Black)", "{!tag=some-tag}productBrand:(Apple)]
Might not be the good way to edit request.rb but couldn't able to find out the alternative way
see request.rb in \ruby\gems\2.2.0\gems\blacklight-6.0.2\lib\blacklight\solr
ref:http://yonik.com/multi-select-faceting/
Example CODE:
def append_filter_query(query)
#$facet_value=query
unless query.nil?
$r= /.*}(.*)/.match(query)[1]
$l=/^({.*})/.match(query)[1]
if self['fq'].empty?
ampati()
else
$flag_new=false
self['fq'].each{|item|
$s=/.*}(.*\w)*:/.match(item)[1]
unless $l.include? $s
#$s=color
$flag_new=true
else
$flag_new=false
end
}
if $flag_new
ampati()
else
self['fq'].map!{|item|
$fac=/.*}(.*\w)*:/.match(item)[1]
if $l.include? $fac
item=/(.*\w)/.match(item)[1]<<" "<<$r<<")"
else
item
end
}
end
end
end
end
def ampati()
if $l.include? "color"
$c="{!tag=color}color:("<<$r<<")"
self['fq']<<$c
end
if $l.include? "productBrand"
$e="{!tag=some-tag}productBrand:("<<$r<<")"
self['fq']<<$e
end
end
Upvotes: 1