MrDys / blacklight

Blacklight Plugin
http://projectblacklight.org/
Other
1 stars 1 forks source link

Blacklight facets do not work with integer-type fields #537

Closed MrDys closed 12 years ago

MrDys commented 12 years ago

CODEBASE-362: Blacklight converts facets from the query string into Solr fq queries using the raw query parser, which does not work right with integer-type fields (Solr 3.2/4.0 introduce the term query parser that (I believe) addresses this problem).

(See https://github.com/projectblacklight/blacklight/blob/master/lib/blacklight/solr_helper.rb#L225 )

From the original report by Rajesh:

Problem:

I have an integer field (square_footage_i) for which I want to use blacklight-range-limit. But even before I integrate that in my app, I am not able to get the associated solr document for that field in the browse view (though I can see all the values for that field populated in the left navigation).

But I get the expected results when I am querying it from solr admin console for any of the following queries: square_footage_i:100000 or square_footage_i:"100000"

To create an integer field, here is what I am doing: I am overriding the to_solr method in my model:

def to_solr(solr_doc = Solr::Document.new, opts={}) doc = super(solr_doc, opts) doc << { :object_type_t => class_name } doc << { :title_t => display_name } .......... doc << { :square_footage_i => square_footage } # square_footage is a method which return int value return doc end

I have set the field in blacklight_config.rb

config[:facet] = { :field_names => (facet_fields = [ "object_type_facet", "code_type_facet", "building_type_facet", "address_section_facet", "square_footage_i" ]), :labels => { "object_type_facet" => "Type", "code_type_facet" => "Code Type", "building_type_facet" => "Building Type", "address_section_facet" => "Section", "square_footage_i" => "Square Footage" },

I have included square_footage_i in the solr_config.rb as well.

I have some debug statements in the rsolr which displayed the following

Query:

[{:"facet.field"=>["object_type_facet", "code_type_facet", "building_type_facet", "address_section_facet", "address_block_facet", "address_lot_facet", "floors_facet", "square_footage_i", "agent_name_name_content_facet", "agent_dates_earliestDate_facet", "agent_dates_latestDate_facet"], :qt=>"public_search", "spellcheck.q"=>nil, :per_page=>10, :fq=>["{!raw f=square_footage_i} 100000"], :sort=>"score desc, year_facet desc, month_facet asc, title_facet asc"}]

SOLR RESPONSE: {"response"=>{"start"=>0, "docs"=>[], "numFound"=>0}, "responseHeader"=>{"QTime"=>5, "params"=>{"fq"=>"{!raw f=square_footage_i}100000", "qt"=>"public_search", "facet.field"=>["object_type_facet", "code_type_facet", "building_type_facet", "address_section_facet", "address_block_facet", "address_lot_facet", "floors_facet", "square_footage_i", "agent_name_name_content_facet", "agent_dates_earliestDate_facet", "agent_dates_latestDate_facet"], "start"=>"0", "wt"=>"ruby", "rows"=>"10", "sort"=>"score desc, year_facet desc, month_facet asc, title_facet asc"}, "status"=>0}, "facet_counts"=>{"facet_fields"=>{"floors_facet"=>[], "agent_dates_latestDate_facet"=>[], "code_type_facet"=>[], "agent_dates_earliestDate_facet"=>[], "address_section_facet"=>[], "square_footage_i"=>[], "agent_name_name_content_facet"=>[], "address_block_facet"=>[], "object_type_facet"=>[], "building_type_facet"=>[], "address_lot_facet"=>[]}, "facet_dates"=>{}, "facet_queries"=>{}}}

MrDys commented 12 years ago

Original reporter: cbeer

MrDys commented 12 years ago

cbeer: http://git.io/SGzkIg