Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

several changes, including warts... almost functional in_place_editor, Solr configuration separation, etc

Erik Hatcher2bc67ded17e7
diff --git a/client/ruby/flare/Rakefile b/client/ruby/flare/Rakefile
index 3bb0e8592a4..ecb7ea3eebd 100644
--- a/client/ruby/flare/Rakefile
+++ b/client/ruby/flare/Rakefile
@@ -8,3 +8,5 @@ require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
+
+require 'solr/solrtasks'
\ No newline at end of file
diff --git a/client/ruby/flare/app/controllers/application.rb b/client/ruby/flare/app/controllers/application.rb
index 540338459a9..861ddc67355 100644
--- a/client/ruby/flare/app/controllers/application.rb
+++ b/client/ruby/flare/app/controllers/application.rb
@@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base
# 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 @@ class ApplicationController < ActionController::Base
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
diff --git a/client/ruby/flare/app/controllers/browse_controller.rb b/client/ruby/flare/app/controllers/browse_controller.rb
index ab8c14d17c0..98a01dd0922 100644
--- a/client/ruby/flare/app/controllers/browse_controller.rb
+++ b/client/ruby/flare/app/controllers/browse_controller.rb
@@ -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 @@ class BrowseController < ApplicationController
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 @@ class BrowseController < ApplicationController
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
diff --git a/client/ruby/flare/app/controllers/simile_controller.rb b/client/ruby/flare/app/controllers/simile_controller.rb
index 834f30a7867..be5aa47d1f6 100755
--- a/client/ruby/flare/app/controllers/simile_controller.rb
+++ b/client/ruby/flare/app/controllers/simile_controller.rb
@@ -16,12 +16,8 @@ class SimileController < ApplicationController
# 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 @@ class SimileController < ApplicationController
# 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)
diff --git a/client/ruby/flare/app/views/browse/facet.rhtml b/client/ruby/flare/app/views/browse/facet.rhtml
index 16b53579aee..29979a0737b 100755
--- a/client/ruby/flare/app/views/browse/facet.rhtml
+++ b/client/ruby/flare/app/views/browse/facet.rhtml
@@ -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%>
\ No newline at end of file
diff --git a/client/ruby/flare/app/views/browse/index.rhtml b/client/ruby/flare/app/views/browse/index.rhtml
index ac7a76f0bed..0fb08a1d534 100644
--- a/client/ruby/flare/app/views/browse/index.rhtml
+++ b/client/ruby/flare/app/views/browse/index.rhtml
@@ -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 @@ Filters:
<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>
diff --git a/client/ruby/flare/app/views/simile/timeline.rxml b/client/ruby/flare/app/views/simile/timeline.rxml
index 48026a53c1f..629e4905a26 100755
--- a/client/ruby/flare/app/views/simile/timeline.rxml
+++ b/client/ruby/flare/app/views/simile/timeline.rxml
@@ -19,7 +19,7 @@ xml.data do
: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"
diff --git a/client/ruby/flare/config/environment.rb b/client/ruby/flare/config/environment.rb
index df49655ca04..794464963ae 100644
--- a/client/ruby/flare/config/environment.rb
+++ b/client/ruby/flare/config/environment.rb
@@ -57,4 +57,8 @@ end
# $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']}")
diff --git a/client/ruby/flare/config/solr.yml b/client/ruby/flare/config/solr.yml
new file mode 100755
index 00000000000..263ef570b15
--- /dev/null
+++ b/client/ruby/flare/config/solr.yml
@@ -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