* 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!).

* With the new DocumentController, a few custom results views have been added, one for UVa data (linking to VIRGO),
  Tang poetry example (blending multiple languages), and a default development one that shows all fields returned
  by Solr.

* Added paging to search results, finally.

* Configured in-place-editor of query to redirect, thereby refreshing the view with the changed criteria.

* Set Simile Exhibit/Timeline field mappings to MARC data example.



git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@511599 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2007-02-25 20:37:06 +00:00
parent 55b6b3db9f
commit b6541aa0a7
11 changed files with 132 additions and 38 deletions

View File

@ -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
@ -21,8 +19,17 @@ class BrowseController < ApplicationController
@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)

View File

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

View File

@ -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><%=@response.total_hits%></strong></div>
<div class="resultsheader">Results <strong><%=@start%>-<%=[@response.total_hits,@results_per_page + @start -1].min%></strong> of <strong><%=@response.total_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><%=@response.total_hits%></strong><%=link_to_if session[:page] < (@response.total_hits.to_f / @results_per_page).ceil, ">>", :page => session[:page] + 1%></div>

View File

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

View File

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

View File

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

View File

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

View File

@ -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/

View File

@ -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)

View File

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

View File

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