|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
apply facet.query feature on FlareHi,
I'm starting to use Flare. I like the idea of @flare is a user session. Thanks to CoC of Flare, if I have *_facet fields, I can have a faceting feature on my application very easily. Please see the following demo: http://www.rondhuit-demo.com/yademo/ The demo uses Japanese commercial goods data instead of Flare library data. Now I want to apply facet.query feature to the demo. To test it, I generated browse2_controller.rb as follows: class Browse2Controller < ApplicationController flare def index @results_per_page = 10 # name => {:queries => [], :filters => []} @flare.facet_queries = { '-49.99'=>{:queries=>['price:[0 TO 49.99]'],:filters=>[]}, '50-99.99'=>{:queries=>['price:[50 TO 99.99]'],:filters=>[]}, '100-99.99'=>{:queries=>['price:[100 TO 299.99]'],:filters=>[]}, '300-'=>{:queries=>['price:[300 TO *]'],:filters=>[]} } if params[:page] @flare.page = params[:page].to_i end @start = (@flare.page - 1) * @results_per_page @response = @flare.search(@start, @results_per_page) end end But no success. When I access browse2/index.rhtml, WEBrick forwards the request to Solr, and Solr log was: /select wt=ruby&facet.limit=20&rows=10&start=0&facet=true&facet.mincount=1 &q=*:*&fl=*,score&qt=standard&facet.query=()&facet.query=()&facet.query=()&facet .query=()&facet.field=category_facet&facet.field=name_facet&fq=category_facet:"e lectronics"&hl=true&facet.sort=true 0 60 How can I use facet.query feature on Flare? Thanks in advance, Koji |
|
|
Re: apply facet.query feature on FlareKoji,
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 :) First a disclaimer: Flare is just a stupid simple hack at this point. Using it for anything other than quick "wow" demos hasn't really been attempted that I'm aware of and it has a ways to go to be where I'd like to see it. Now on to your question... On Oct 28, 2007, at 12:51 AM, Koji Sekiguchi wrote: > I'm starting to use Flare. I like the idea of @flare is a user > session. I'd like to see this evolve into multiple flare contexts possible per session. > class Browse2Controller < ApplicationController > flare > def index > @results_per_page = 10 > > # name => {:queries => [], :filters => []} > @flare.facet_queries = { > '-49.99'=>{:queries=>['price:[0 TO 49.99]'],:filters=>[]}, > '50-99.99'=>{:queries=>['price:[50 TO 99.99]'],:filters=>[]}, > '100-99.99'=>{:queries=>['price:[100 TO 299.99]'],:filters=>[]}, > '300-'=>{:queries=>['price:[300 TO *]'],:filters=>[]} > } > > if params[:page] > @flare.page = params[:page].to_i > end > > @start = (@flare.page - 1) * @results_per_page > > @response = @flare.search(@start, @results_per_page) > end > end > How can I use facet.query feature on Flare? I just cobbled this example of an index method that sets the facet_queries: def index @flare.facet_queries = {"foo"=>{:filters=>[], :queries=> [{:query=>"whatever"}]}} @response = @flare.search(@start, @results_per_page) end Notice the :queries needs to be an array of Hashes with :query set in each one. This allows for inverting the query by adding :negative => true also. In my example, you get this back in the response: 'facet_counts'=>{'facet_queries'=>{'(whatever)'=>4} The key for the 'facet_queries' is the converted Lucene query, with parens wrapped around it. The Flare demo app displays these by leveraging the :real_query that gets added under the covers, like this: <% @flare.facet_queries.each do |name,value| count = @response.data['facet_counts']['facet_queries'][value [:real_query]] %> A bit ugly, indeed, but it works for what it's worth. > Thanks in advance, Thank you for giving Flare some attention :) There is some energy coming to Flare from some other projects, notably Blacklight at http://blacklight.betech.virginia.edu so I think we'll see some patches coming from there soon. Erik |
|
|
Re: apply facet.query feature on FlareErik,
> 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 |
| Free embeddable forum powered by Nabble | Forum Help |