Skip to content

Apache Lucene open-source search software

* Added DocumentController to control search results detail rendering. SOLR_ENV selects one of the Solr environment configuration mappings defined in environment.rb ('development' by default). solr.yml eliminated (Ruby is a fine configuration language!).

Erik Hatcherb6541aa0a711
diff --git a/client/ruby/flare/app/controllers/browse_controller.rb b/client/ruby/flare/app/controllers/browse_controller.rb
index 98a01dd0922..40107162ffa 100644
--- a/client/ruby/flare/app/controllers/browse_controller.rb
+++ b/client/ruby/flare/app/controllers/browse_controller.rb
@@ -4,8 +4,6 @@
class BrowseController < ApplicationController
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
@@ -20,9 +18,18 @@ class BrowseController < ApplicationController
@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$/}
-
+
+ session[:page] = params[:page].to_i if params[:page]
+ session[:page] = 1 if session[:page] <= 0
+
+ @results_per_page = 25
+
+ @start = (session[:page] - 1) * @results_per_page + 1
+
request = Solr::Request::Standard.new(:query => query,
:filter_queries => filters,
+ :rows => @results_per_page,
+ :start => @start,
: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)
@@ -50,7 +57,9 @@ class BrowseController < ApplicationController
def update_query
logger.debug "update_query: #{params.inspect}"
session[:queries][params[:index].to_i][:query] = params[:value]
- render :layout => false, :text => params[:value]
+ render :update do |page|
+ page.redirect_to '/browse'
+ end
end
def invert_query
@@ -83,6 +92,7 @@ class BrowseController < ApplicationController
def clear
session[:queries] = nil
session[:filters] = nil
+ session[:page] = 1
flare_before
redirect_to :action => 'index'
end
@@ -91,6 +101,7 @@ class BrowseController < ApplicationController
def flare_before
session[:queries] ||= []
session[:filters] ||= []
+ session[:page] ||= 1
end
def retrieve_field_facets(field, limit=-1, prefix=nil)
diff --git a/client/ruby/flare/app/controllers/document_controller.rb b/client/ruby/flare/app/controllers/document_controller.rb
new file mode 100755
index 00000000000..4a8ed0c1165
--- /dev/null
+++ b/client/ruby/flare/app/controllers/document_controller.rb
@@ -0,0 +1,20 @@
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+class DocumentController < ApplicationController
+ def result
+ @doc = params[:doc]
+ @response = params[:response] # TODO: FlareContext?
+ render :template => "document/document_#{SOLR_ENV}"
+ end
+end
diff --git a/client/ruby/flare/app/views/browse/index.rhtml b/client/ruby/flare/app/views/browse/index.rhtml
index 7220782576f..65343de8f2d 100644
--- a/client/ruby/flare/app/views/browse/index.rhtml
+++ b/client/ruby/flare/app/views/browse/index.rhtml
@@ -37,7 +37,7 @@
<% session[:queries].each_with_index do |q,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) %>
+<%= in_place_editor "query_#{i}", :url=> url_for(:action=>"update_query", :index=>i, :script=>true) %>
<%=link_to image_tag("x-close.gif"), :action => :remove_query, :index => i %><br/>
<% end %>
</div>
@@ -60,27 +60,17 @@
</div>
-<div class="resultsheader">Results <strong>1-<%=[@response.total_hits,10].min%></strong> of <strong><%[email protected]_hits%></strong></div>
-
+<div class="resultsheader">Results <strong><%=@start%>-<%=[@response.total_hits,@results_per_page + @start -1].min%></strong> of <strong><%[email protected]_hits%></strong></div>
<div id="results"><table cellpadding="10">
<% @response.each do |doc| %>
-<tr valign="top">
- <td>
- <table class="entry">
- <tr>
- <td class="title" colspan="2"><%=doc['title_text']%></td>
- </tr>
- <% doc.each do |k,v|; highlighting = @response.highlighted(doc['id'], k) %>
- <tr><td class="field"><%=k%>:</td><td><%= highlighting ? "...#{highlighting}..." : (v.respond_to?('join') ? v.join(',') : v.to_s)%></td></tr>
- <% end %>
- </table>
- </td>
-</tr>
+ <%= render_component :controller => DocumentController, :action => "result", :params => {:doc => doc, :response => @response} %>
<% end %>
</table>
</div>
+<div class="resultsheader"><%=link_to_if session[:page] != 1, "<<", :page => session[:page] - 1%> Results <strong><%=@start%>-<%=[@response.total_hits,@results_per_page + @start -1].min%></strong> of <strong><%[email protected]_hits%></strong><%=link_to_if session[:page] < (@response.total_hits.to_f / @results_per_page).ceil, ">>", :page => session[:page] + 1%></div>
+
diff --git a/client/ruby/flare/app/views/document/document_development.rhtml b/client/ruby/flare/app/views/document/document_development.rhtml
new file mode 100755
index 00000000000..d99f4a9d7b0
--- /dev/null
+++ b/client/ruby/flare/app/views/document/document_development.rhtml
@@ -0,0 +1,12 @@
+<tr valign="top">
+ <td>
+ <table class="entry">
+ <tr>
+ <td class="title" colspan="2"><%=@doc['title_text']%></td>
+ </tr>
+ <% @doc.each do |k,v|; highlighting = @response.highlighted(@doc['id'], k) %>
+ <tr><td class="field"><%=k%>:</td><td><%= highlighting ? "...#{highlighting}..." : (v.respond_to?('join') ? v.join(',') : v.to_s)%></td></tr>
+ <% end %>
+ </table>
+ </td>
+</tr>
diff --git a/client/ruby/flare/app/views/document/document_tang.rhtml b/client/ruby/flare/app/views/document/document_tang.rhtml
new file mode 100755
index 00000000000..0dc7fde6843
--- /dev/null
+++ b/client/ruby/flare/app/views/document/document_tang.rhtml
@@ -0,0 +1,30 @@
+<%
+ body_zh_highlighted = @response.highlighted(@doc['id'], 'body_zh_text')
+ body_en_highlighted = @response.highlighted(@doc['id'], 'body_en_text')
+-%>
+<tr valign="top">
+ <td>
+ <table class="entry">
+ <tr>
+ <td class="title" colspan="2"><%=@doc['title_zh_text']%> (<%=@doc['title_en_text']%>)</td>
+ </tr>
+ <tr>
+ <td class="field">author:</td><td><%=@doc['author_zh_facet']%> (<%=@doc['author_en_facet']%>)</td>
+ </tr>
+ <tr>
+ <td class="field">type:</td><td><%=@doc['type_zh_facet']%> (<%=@doc['type_en_facet']%>)</td>
+ </tr>
+ <tr>
+ <td class="field">body:</td>
+ <td>
+ <blockquote>
+ <%= body_zh_highlighted ? "...#{body_zh_highlighted}..." : @doc['body_zh_text'] %>
+ </blockquote>
+ <blockquote>
+ <%= body_en_highlighted ? "...#{body_en_highlighted}..." : @doc['body_en_text'] %>
+ </blockquote>
+ </td>
+ </tr>
+ </table>
+ </td>
+</tr>
diff --git a/client/ruby/flare/app/views/document/document_uva.rhtml b/client/ruby/flare/app/views/document/document_uva.rhtml
new file mode 100755
index 00000000000..fe454ae4fca
--- /dev/null
+++ b/client/ruby/flare/app/views/document/document_uva.rhtml
@@ -0,0 +1,23 @@
+<%
+ virgo_link = "http://virgo.lib.virginia.edu/uhtbin/cgisirsi/uva/0/0/5?searchdata1=#{@doc['id'][1..-1]}%7bCKEY%7d"
+ # url = URI.parse(virgo_link)
+ # res = Net::HTTP.start(url.host, url.port) {|http|
+ # http.get("/uhtbin/cgisirsi/uva/0/0/5?searchdata1=#{@doc['id'][1..-1]}{CKEY}")
+ # }
+ # availability = Regexp.new("Copy\ info\:(.*)td\>", Regexp::MULTILINE).match(res.body)[1]
+%>
+<tr valign="top">
+ <td>
+ <table class="entry">
+ <tr>
+ <td class="title" colspan="2"><%= link_to @doc['title_text'], virgo_link, {:target => "_blank"}%></td>
+ </tr>
+ <% @doc.each do |k,v|; highlighting = @response.highlighted(@doc['id'], k) %>
+ <tr><td class="field"><%=k%>:</td><td><%= highlighting ? "...#{highlighting}..." : (v.respond_to?('join') ? v.join(',') : v.to_s)%></td></tr>
+ <% end %>
+ <tr>
+ <!-- <td class="field">Availability:</td><td><%%=h availability%></td> -->
+ </tr>
+ </table>
+ </td>
+</tr>
diff --git a/client/ruby/flare/app/views/simile/exhibit.rhtml b/client/ruby/flare/app/views/simile/exhibit.rhtml
index e0a76862772..bdf54e81d16 100644
--- a/client/ruby/flare/app/views/simile/exhibit.rhtml
+++ b/client/ruby/flare/app/views/simile/exhibit.rhtml
@@ -16,7 +16,7 @@
<div id="exhibit-view-panel"></div>
</td>
<td width="25%">
- <div id="exhibit-browse-panel" ex:facets=".genre_facet, .medium_facet, .country_facet, .signed_facet, .rating_facet, .language_facet"></div>
+ <div id="exhibit-browse-panel" ex:facets=".subject_genre_facet, .subject_era_facet, .subject_topic_facet, .subject_geographic_facet, .year_facet"></div>
</td>
</tr>
</table>
diff --git a/client/ruby/flare/app/views/simile/timeline.rxml b/client/ruby/flare/app/views/simile/timeline.rxml
index 629e4905a26..6ce3d2fcdea 100755
--- a/client/ruby/flare/app/views/simile/timeline.rxml
+++ b/client/ruby/flare/app/views/simile/timeline.rxml
@@ -13,10 +13,9 @@
xml.data do
@data.each do |doc|
xml.event(doc['title_text'],
- :start => doc['published_year_facet'],
- :end => doc['published_year_facet'],
- :title => doc['title_text'],
- :image => "#{doc['asin_text']}")
+ :start => doc['year_facet'],
+ :end => doc['year_facet'],
+ :title => doc['title_text'])
end
end
# Amazon images: http://www.betaversion.org/~stefano/linotype/news/66/
diff --git a/client/ruby/flare/config/environment.rb b/client/ruby/flare/config/environment.rb
index 794464963ae..471e034e963 100644
--- a/client/ruby/flare/config/environment.rb
+++ b/client/ruby/flare/config/environment.rb
@@ -57,8 +57,24 @@ end
# $KCODE = 'UTF8' # Rails 1.2 supposedly sets this automatically
require 'solr'
-solr_environments = YAML.load_file("#{RAILS_ROOT}/config/solr.yml")
+
+
+
+solr_environments = {
+ :development => {
+ },
+
+ :uva => {
+ },
+
+ :delicious => {
+ },
+
+ :tang => {
+ }
+}
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']}")
+SOLR_CONFIG = solr_environments[SOLR_ENV.to_sym]
+puts "#{SOLR_ENV}: SOLR_CONFIG = #{SOLR_CONFIG.inspect}"
+solr_url = SOLR_CONFIG[:solr_url] || "http://localhost:8983/solr"
+SOLR = Solr::Connection.new(solr_url)
diff --git a/client/ruby/flare/config/solr.yml b/client/ruby/flare/config/solr.yml
deleted file mode 100755
index 263ef570b15..00000000000
--- a/client/ruby/flare/config/solr.yml
+++ /dev/null
@@ -1,8 +0,0 @@
-development:
- solr_url: http://localhost:8983/solr
-
-delicious:
- solr_url: http://localhost:8985/solr
-
-tang:
- solr_url: http://localhost:8987/solr
diff --git a/client/ruby/flare/script/pie.rb b/client/ruby/flare/script/pie.rb
index 44991459873..7f9d94403cd 100755
--- a/client/ruby/flare/script/pie.rb
+++ b/client/ruby/flare/script/pie.rb
@@ -17,8 +17,9 @@ require 'sparklines'
0.upto(100) do |i|
Sparklines.plot_to_file("public/images/pie_#{i}.png",
[i], :type => 'pie',
- :share_color => "blue"
- # :remain_color => "#dcdcdc", :background_color => "#ededed"
+ :share_color => "#D43D1A",
+ :remain_color => "#dcdcdc"
+# :background_color => "#ededed"
)
end