Erik,

> Nice to see you here! I have recently noticed your work with Flare and been very pleased to see someone give it a try besides myself :)

I'm pleased to see you here, too!

Struggling a few hours, I can implement facet.query feature on my demo:

http://www.rondhuit-demo.com/yademo/

Here is what I did:

1. rename "facet_queries" to "saved_queries" and
 "applied_facet_queries" to "applied_saved_queries"
(Why I did this because first I used @facet_queries to have
facet.query and it was success except that facet query links
were displayed at "saved searches" area)

2. initialize @facet_queries by having:
   @flare.facet_queries = {
     '1-1,000'=>{:queries=>[{:query=>'price:[1 TO 1000]'}],:filters=>[]},
'1,001-5,000'=>{:queries=>[{:query=>'price:[1001 TO 5000]'}],:filters=>[]}, '5,001-10,000'=>{:queries=>[{:query=>'price:[5,001 TO 10000]'}],:filters=>[]}, '10,001-20,000'=>{:queries=>[{:query=>'price:[10,001 TO 20000]'}],:filters=>[]},
     '20,001-'=>{:queries=>[{:query=>'price:[20001 TO *]'}],:filters=>[]}
}
3. have the following in search() method:
   facet_queries = @facet_queries.collect do |k,v|
     clauses = filter_queries(v[:filters])
     clauses << build_boolean_query(v[:queries])
     query = clauses.join(" AND ")
     @facet_queries[k][:real_query] = query
     query
   end

4. and use the above with saved_queries when assembling solr_params:
#           :queries => saved_queries
          :queries => saved_queries.concat(facet_queries)

5. have the following "price facet" display in browse/index.rhtml:
<h4>
 price
</h4>
<ul>
<% @flare.facet_queries.each do |name,value|
count = @response.data['facet_counts']['facet_queries'][value[:real_query]]
   if count > 0
       field_value = value[:queries][0][:query]
%>
<li>
<%= image_tag "pie_#{(count * 100.0 / @response.total_hits).ceil rescue 0}.png"%> <%= link_to "#{name} (#{count})", :action => 'add_filter', :field=>field_value.sub(/:.*$/,''), :value=>field_value.sub(/^.*:/,'')%>
</li>
   <% end %>
<% end %>
</ul>

6. finally, I have to change filter_queries() method as follows to avoid NumberFormatException when clicking one of price facet link(java.lang.NumberFormatException: For input string: \"[10001 TO 20000]\"):
#        value = "\"#{value}\""
       value = "#{value}"


Next, I'll have date faceting feature to the demo. Also, the price facet links should be sorted.

Thank you again, Erik!

Koji

Reply via email to