You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by eh...@apache.org on 2007/02/18 21:22:11 UTC

svn commit: r508978 - in /lucene/solr/trunk/client/ruby/flare: ./ app/controllers/ app/views/browse/ app/views/simile/ config/

Author: ehatcher
Date: Sun Feb 18 12:22:10 2007
New Revision: 508978

URL: http://svn.apache.org/viewvc?view=rev&rev=508978
Log:
several changes, including warts... almost functional in_place_editor, Solr configuration separation, etc

Added:
    lucene/solr/trunk/client/ruby/flare/config/solr.yml   (with props)
Modified:
    lucene/solr/trunk/client/ruby/flare/Rakefile
    lucene/solr/trunk/client/ruby/flare/app/controllers/application.rb
    lucene/solr/trunk/client/ruby/flare/app/controllers/browse_controller.rb
    lucene/solr/trunk/client/ruby/flare/app/controllers/simile_controller.rb
    lucene/solr/trunk/client/ruby/flare/app/views/browse/facet.rhtml
    lucene/solr/trunk/client/ruby/flare/app/views/browse/index.rhtml
    lucene/solr/trunk/client/ruby/flare/app/views/simile/timeline.rxml
    lucene/solr/trunk/client/ruby/flare/config/environment.rb

Modified: lucene/solr/trunk/client/ruby/flare/Rakefile
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/Rakefile?view=diff&rev=508978&r1=508977&r2=508978
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/Rakefile (original)
+++ lucene/solr/trunk/client/ruby/flare/Rakefile Sun Feb 18 12:22:10 2007
@@ -8,3 +8,5 @@
 require 'rake/rdoctask'
 
 require 'tasks/rails'
+
+require 'solr/solrtasks'
\ No newline at end of file

Modified: lucene/solr/trunk/client/ruby/flare/app/controllers/application.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/app/controllers/application.rb?view=diff&rev=508978&r1=508977&r2=508978
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/app/controllers/application.rb (original)
+++ lucene/solr/trunk/client/ruby/flare/app/controllers/application.rb Sun Feb 18 12:22:10 2007
@@ -8,7 +8,7 @@
   # Pick a unique cookie name to distinguish our session data from others'
   session :session_key => '_flare_session_id'
 
-
+private
   def query
     queries = session[:queries]
     if queries.nil? || queries.empty?
@@ -21,7 +21,18 @@
   end
   
   def filters
-    session[:filters].collect {|filter| "#{filter[:negative] ? '-' : ''}#{filter[:field]}:\"#{filter[:value]}\""}
+    session[:filters].collect do |filter|
+      value = filter[:value]
+      if value != "[* TO *]"
+        value = "\"#{value}\""
+      end
+      "#{filter[:negative] ? '-' : ''}#{filter[:field]}:#{value}"
+    end
+  end
+  
+  def solr(request)
+    logger.info "---\n#{request.inspect}\n---"
+    SOLR.send(request)  
   end
 
 end

Modified: lucene/solr/trunk/client/ruby/flare/app/controllers/browse_controller.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/app/controllers/browse_controller.rb?view=diff&rev=508978&r1=508977&r2=508978
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/app/controllers/browse_controller.rb (original)
+++ lucene/solr/trunk/client/ruby/flare/app/controllers/browse_controller.rb Sun Feb 18 12:22:10 2007
@@ -2,17 +2,31 @@
 # License::   Apache Version 2.0 (see http://www.apache.org/licenses/)
 
 class BrowseController < ApplicationController
-  before_filter :setup_session
-
+  before_filter :flare_before
+  
+  # TODO: use in-place-editor for queries, allowing editing of them (instead of remove and re-add new one)
+  
+  # def self.flare(options={})
+  #   define_method() do
+  #   end
+  # end
+  # 
+  # flare do |f|
+  #   f.facet_fields = []
+  # end
+  
   def index
-    @info = SOLR.send(Solr::Request::IndexInfo.new) # TODO move this call to only have it called when the index may have changed
-    @facet_fields = @info.field_names.find_all {|v| v =~ /_facet$/}
-    
     # TODO Add paging and sorting
-    request = Solr::Request::Standard.new :query => query,
+    @info = solr(Solr::Request::IndexInfo.new) # TODO move this call to only have it called when the index may have changed
+    @facet_fields = @info.field_names.find_all {|v| v =~ /_facet$/}
+    @text_fields = @info.field_names.find_all {|v| v =~ /_text$/}
+
+    request = Solr::Request::Standard.new(:query => query,
                                           :filter_queries => filters,
-                                          :facets => {:fields => @facet_fields, :limit => 20 , :mincount => 1, :sort => :count, :debug_query=>true}
-    @response = SOLR.send(request)                                          
+                                          :facets => {:fields => @facet_fields, :limit => 20 , :mincount => 1, :sort => :count, :debug_query=>true},
+                                          :highlighting => {:field_list => @text_fields})
+    logger.info({:query => query, :filter_queries => filters}.inspect)
+    @response = solr(request)
     
     #TODO: call response.field_facets(??) - maybe field_facets should be return a higher level? 
   end
@@ -28,12 +42,17 @@
     render :partial => 'suggest'
   end
 
-
   def add_query
     session[:queries] << {:query => params[:search][:query]}
     redirect_to :action => 'index'
   end
   
+  def update_query
+    logger.debug "update_query: #{params.inspect}"
+    session[:queries][params[:index].to_i][:query] = params[:value]
+    render :layout => false, :text => params[:value]
+  end
+
   def invert_query
     q = session[:queries][params[:index].to_i]
     q[:negative] = !q[:negative]
@@ -57,19 +76,19 @@
   end
   
   def add_filter
-    session[:filters] << {:field => params[:field_name], :value => params[:value]} 
+    session[:filters] << {:field => params[:field_name], :value => params[:value], :negative => (params[:negative] ? true : false)} 
     redirect_to :action => 'index'
   end
   
   def clear
     session[:queries] = nil
     session[:filters] = nil
-    setup_session
+    flare_before
     redirect_to :action => 'index'
   end
   
   private
-  def setup_session
+  def flare_before
     session[:queries] ||= [] 
     session[:filters] ||= []
   end

Modified: lucene/solr/trunk/client/ruby/flare/app/controllers/simile_controller.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/app/controllers/simile_controller.rb?view=diff&rev=508978&r1=508977&r2=508978
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/app/controllers/simile_controller.rb (original)
+++ lucene/solr/trunk/client/ruby/flare/app/controllers/simile_controller.rb Sun Feb 18 12:22:10 2007
@@ -16,12 +16,8 @@
     # TODO this code was copied from BrowseController#index, and is here only as a quick and dirty prototype.
     # TODO figuring out where these calls cleanly belong is the key.
     
-    @info = SOLR.send(Solr::Request::IndexInfo.new) # TODO move this call to only have it called when the index may have changed
-    @facet_fields = @info.field_names.find_all {|v| v =~ /_facet$/}
-    
-    req = Solr::Request::Standard.new :query => query,
-                                          :filter_queries => filters,
-                                          :facets => {:fields => @facet_fields, :limit => 20 , :mincount => 1, :sort => :count, :debug_query=>true}
+    req = Solr::Request::Standard.new :query => query, :filter_queries => filters
+                                          
     @data = SOLR.send(req)
     
     # Exhibit seems to require a label attribute to be happy
@@ -38,11 +34,8 @@
     # TODO figuring out where these calls cleanly belong is the key.
     
     @info = SOLR.send(Solr::Request::IndexInfo.new) # TODO move this call to only have it called when the index may have changed
-    @facet_fields = @info.field_names.find_all {|v| v =~ /_facet$/}
-    
-    req = Solr::Request::Standard.new :query => query,
-                                          :filter_queries => filters,
-                                          :facets => {:fields => @facet_fields, :limit => 20 , :mincount => 1, :sort => :count, :debug_query=>true}
+    req = Solr::Request::Standard.new :query => query, :filter_queries => filters
+                                          
     @data = SOLR.send(req)
     
     

Modified: lucene/solr/trunk/client/ruby/flare/app/views/browse/facet.rhtml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/app/views/browse/facet.rhtml?view=diff&rev=508978&r1=508977&r2=508978
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/app/views/browse/facet.rhtml (original)
+++ lucene/solr/trunk/client/ruby/flare/app/views/browse/facet.rhtml Sun Feb 18 12:22:10 2007
@@ -1,3 +1,7 @@
 <% @facets.each do |f| %>
-  <%= link_to (f.name ? f.name : '#### NO VALUE ###'), :action => 'add_filter', :field_name => params[:field_name], :value => f.name %> (<%=f.value%>)
+  <% if f.name %>
+    <%= link_to f.name, :action => 'add_filter', :field_name => params[:field_name], :value => f.name %> (<%=f.value%>)
+  <% else %>
+    <%= link_to '---- NO VALUE ----', :action => 'add_filter', :field_name => params[:field_name], :value => "[* TO *]", :negative => true %> (<%=f.value%>)
+  <% end %>
 <% end%>

Modified: lucene/solr/trunk/client/ruby/flare/app/views/browse/index.rhtml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/app/views/browse/index.rhtml?view=diff&rev=508978&r1=508977&r2=508978
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/app/views/browse/index.rhtml (original)
+++ lucene/solr/trunk/client/ruby/flare/app/views/browse/index.rhtml Sun Feb 18 12:22:10 2007
@@ -7,6 +7,7 @@
 
 <% @facet_fields.each do |field|%>
   <h4><%=link_to field, :action => 'facet', :field_name => field%></h4>
+  
   <ul>
   <% @response.field_facets(field).each do |f| %>
     <li>
@@ -22,7 +23,10 @@
 <div>
 Queries:
 <% session[:queries].each_with_index do |q,i| %>
-   <%=link_to q[:negative] ? "-" : '+', :action => :invert_query, :index => i%> <%=q[:query]%> <%=link_to image_tag("x-close.gif"), :action => :remove_query, :index => i %>
+<%=link_to q[:negative] ? "-" : '+', :action => :invert_query, :index => i%>
+<span id="query_<%=i%>"><%=q[:query]%></span>
+<%= in_place_editor "query_#{i}", :url=> url_for(:action=>"update_query", :index=>i) %>
+<%=link_to image_tag("x-close.gif"), :action => :remove_query, :index => i %>
 <% end %>
 </div>
 <div>
@@ -39,12 +43,15 @@
 
 
 <div id="results"><table cellpadding="10">
-  <% display_fields = [:title, :author, :pages, :rating]; @response.each do |doc| %>
+  <% @response.each do |doc| %>
 <tr valign="top">
   <td>
     <table>
-      <% display_fields.each do |f|%>
-      <tr><th><%=f.to_s%></th><td><%=doc["#{f.to_s}_text"] %><%=doc["#{f.to_s}_facet"] %></td></tr>
+      <tr colspan="2">
+        <th><%=doc['title_text']%></th>
+      </tr>
+      <% doc.each do |k,v|; highlighting = @response.highlighted(doc['id'], k) %>
+      <tr><td><%=k%>:</td><td><%= highlighting ? "...#{highlighting}..." : v%></td></tr>
       <% end %>
     </table>
   </td>

Modified: lucene/solr/trunk/client/ruby/flare/app/views/simile/timeline.rxml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/app/views/simile/timeline.rxml?view=diff&rev=508978&r1=508977&r2=508978
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/app/views/simile/timeline.rxml (original)
+++ lucene/solr/trunk/client/ruby/flare/app/views/simile/timeline.rxml Sun Feb 18 12:22:10 2007
@@ -19,7 +19,7 @@
       :image => "#{doc['asin_text']}")
   end
 end
-
+# Amazon images: http://www.betaversion.org/~stefano/linotype/news/66/
 # <data>
 #     <event 
 #         start="May 28 2006 09:00:00 GMT"

Modified: lucene/solr/trunk/client/ruby/flare/config/environment.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/config/environment.rb?view=diff&rev=508978&r1=508977&r2=508978
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/config/environment.rb (original)
+++ lucene/solr/trunk/client/ruby/flare/config/environment.rb Sun Feb 18 12:22:10 2007
@@ -57,4 +57,8 @@
 # $KCODE = 'UTF8' # Rails 1.2 supposedly sets this automatically
 
 require 'solr'
-SOLR = Solr::Connection.new("http://localhost:8983/solr")
+solr_environments = YAML.load_file("#{RAILS_ROOT}/config/solr.yml")
+SOLR_ENV = ENV["SOLR_ENV"] || "development"
+SOLR_CONFIG = solr_environments[SOLR_ENV]
+puts "SOLR_CONFIG = #{SOLR_CONFIG.to_yaml}"
+SOLR = Solr::Connection.new("#{SOLR_CONFIG['solr_url']}")

Added: lucene/solr/trunk/client/ruby/flare/config/solr.yml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/config/solr.yml?view=auto&rev=508978
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/config/solr.yml (added)
+++ lucene/solr/trunk/client/ruby/flare/config/solr.yml Sun Feb 18 12:22:10 2007
@@ -0,0 +1,8 @@
+development:
+  solr_url: http://localhost:8983/solr
+  
+delicious:
+  solr_url: http://localhost:8985/solr
+
+tang:
+  solr_url: http://localhost:8987/solr

Propchange: lucene/solr/trunk/client/ruby/flare/config/solr.yml
------------------------------------------------------------------------------
    svn:executable = *