lucene-ruby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Koji Sekiguchi <>
Subject Re: apply facet.query feature on Flare
Date Tue, 30 Oct 2007 01:03:03 GMT

 > 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:

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 
      '5,001-10,000'=>{:queries=>[{:query=>'price:[5,001 TO 
      '10,001-20,000'=>{:queries=>[{:query=>'price:[10,001 TO 
      '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

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:
<% @flare.facet_queries.each do |name,value|
    count =['facet_counts']['facet_queries'][value[:real_query]]
    if count > 0
        field_value = value[:queries][0][:query]
  <%= 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(/^.*:/,'')%>
    <% end %>
<% end %>

6. finally, I have to change filter_queries() method as follows to avoid 
   when clicking one of price facet 
link(java.lang.NumberFormatException: For input string: \"[10001 TO 
#        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!


View raw message