Apache Lucene open-source search software
Take advantage of flare as a plugin, removing code that is now in the plugin
Erik Hatcherb781ee877591
diff --git a/client/ruby/flare/app/controllers/application.rb b/client/ruby/flare/app/controllers/application.rbindex 82d55ba9d28..f00ff230cd7 100644--- a/client/ruby/flare/app/controllers/application.rb+++ b/client/ruby/flare/app/controllers/application.rb@@ -24,7 +24,7 @@ privatedef flare_beforesession[:page] ||= 1- session[:flare_context] ||= FlareContext.new(SOLR_CONFIG)+ session[:flare_context] ||= Flare::Context.new(SOLR_CONFIG)@flare = session[:flare_context]enddiff --git a/client/ruby/flare/app/controllers/browse_controller.rb b/client/ruby/flare/app/controllers/browse_controller.rbindex 536213a6d81..173d798c0f5 100644--- a/client/ruby/flare/app/controllers/browse_controller.rb+++ b/client/ruby/flare/app/controllers/browse_controller.rb@@ -1,129 +1,15 @@-# Copyright:: Copyright (c) 2007 Apache Software Foundation-# License:: Apache Version 2.0 (see http://www.apache.org/licenses/)+# 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 BrowseController < ApplicationController- # def self.flare(options={})- # define_method() do- # end- # end- #- # flare do |f|- # f.facet_fields = []- # end-- def index- 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-- @response = @flare.search(@start, @results_per_page)- end-- def facet- puts "---- facet: #{params[:field]}"- @facets = @flare.retrieve_field_facets(params[:field])- end-- def auto_complete_for_search_query- # TODO instead of "text", default to the default search field configured in schema.xml- @values = @flare.retrieve_field_facets("text", 5, params['search']['query'].downcase)-- render :partial => 'suggest'- end--- def add_query- @flare.queries << {:query => params[:search][:query]}- session[:page] = 1- redirect_to :action => 'index'- end-- def update_query- logger.debug "update_query: #{params.inspect}"- @flare.queries[params[:index].to_i][:query] = params[:value]- session[:page] = 1- render :update do |page|- page.redirect_to '/browse'- end- end-- def invert_query- q = @flare.queries[params[:index].to_i]- q[:negative] = !q[:negative]- session[:page] = 1- redirect_to :action => 'index'- end-- def remove_query- @flare.queries.delete_at(params[:index].to_i)- session[:page] = 1- redirect_to :action => 'index'- end-- def invert_filter- f = @flare.filters[params[:index].to_i]- f[:negative] = !f[:negative]- session[:page] = 1- redirect_to :action => 'index'- end-- def remove_filter- @flare.filters.delete_at(params[:index].to_i)- session[:page] = 1- redirect_to :action => 'index'- end-- def add_filter- @flare.filters << {:field => params[:field], :value => params[:value], :negative => (params[:negative] ? true : false)}- session[:page] = 1- redirect_to :action => 'index'- end-- def add_saved_search- @flare.applied_facet_queries << {:name => params[:name], :negative => (params[:negative] ? true : false)}- redirect_to :action => 'index'- end-- def remove_saved_constraint- @flare.applied_facet_queries.delete_at(params[:index].to_i)- session[:page] = 1- redirect_to :action => 'index'- end-- def clear- @flare.clear- redirect_to :action => 'index'- end-- def show_saved- query = @flare.facet_queries[params[:name]]- @flare.applied_facet_queries << {:name => params[:name], :negative => (params[:negative] ? true : false)}- index- render :action => 'index'- end-- def save- @flare.facet_queries[params[:name]] = {:filters => @flare.filters.clone, :queries => @flare.queries.clone}- redirect_to :action => 'index'- end-- def remove_saved_search- puts "---- BEFORE", @flare.to_s- @flare.facet_queries.delete(params[:name])- @flare.applied_facet_queries.delete_if {|f| params[:name] == f[:name]}- puts "---- AFTER", @flare.to_s- session[:page] = 1- redirect_to :action => 'index'- end-- def invert_saved_constraint- f = @flare.applied_facet_queries[params[:index].to_i]- f[:negative] = !f[:negative]- session[:page] = 1- redirect_to :action => 'index'- end-+ flareenddiff --git a/client/ruby/flare/app/views/browse/index.rhtml b/client/ruby/flare/app/views/browse/index.rhtmlindex 62036529555..fb3b487bdfd 100644--- a/client/ruby/flare/app/views/browse/index.rhtml+++ b/client/ruby/flare/app/views/browse/index.rhtml@@ -89,6 +89,10 @@</div>+<% if @flare.empty_constraints? %>+click click click+<% else %>+<div class="resultsheader">Results <strong><%=[@start + 1,@response.total_hits].min%>-<%=[@response.total_hits,@results_per_page + @start].min%></strong> of <strong><%[email protected]_hits%></strong></div><div id="results"><table cellpadding="10">@@ -100,3 +104,4 @@<div class="resultsheader"><%=link_to_if session[:page] != 1, "<<", :page => session[:page] - 1%> Results <strong><%=[@start + 1,@response.total_hits].min%>-<%=[@response.total_hits,@results_per_page + @start].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>+<% end %>\ No newline at end of filediff --git a/client/ruby/flare/lib/flare_context.rb b/client/ruby/flare/lib/flare_context.rbdeleted file mode 100755index bdba348fd4a..00000000000--- a/client/ruby/flare/lib/flare_context.rb+++ /dev/null@@ -1,122 +0,0 @@-# 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.--# TODO Add sorting-class FlareContext- attr_accessor :queries, :filters, :facet_queries, :applied_facet_queries- attr_reader :facet_fields, :text_fields-- def initialize(solr_config)- @solr_config = solr_config- @connection = Solr::Connection.new(@solr_config[:solr_url])-- clear- @facet_queries = {} # name => {:queries => [], :filters => []}-- @index_info = @connection.send(Solr::Request::IndexInfo.new)-- excluded = @solr_config[:facets_exclude] ? @solr_config[:facets_exclude].collect {|e| e.to_s} : []- @facet_fields = @index_info.field_names.find_all {|v| v =~ /_facet$/} - excluded-- @text_fields = @index_info.field_names.find_all {|v| v =~ /_text$/}- end-- def clear- @queries = []- @filters = []- @applied_facet_queries = []-- # this is cleared for development purposes - allowing flare to stay running but different Solr datasets swapping- @index_info = @connection.send(Solr::Request::IndexInfo.new)- excluded = @solr_config[:facets_exclude] ? @solr_config[:facets_exclude].collect {|e| e.to_s} : []- @facet_fields = @index_info.field_names.find_all {|v| v =~ /_facet$/} - excluded- @text_fields = @index_info.field_names.find_all {|v| v =~ /_text$/}-- # facet_queries not cleared as their lifetime is different than constraints- end-- def empty_constraints?- @queries.empty? && @filters.empty? && @applied_facet_queries.empty?- end-- def search(start, max)- 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-- qa = applied_facet_queries.collect {|map| q = @facet_queries[map[:name]][:real_query]; map[:negative] ? "-(#{q})" : q}- qa << build_boolean_query(@queries)- request = Solr::Request::Standard.new(:query => qa.join(" AND "),- :filter_queries => filter_queries(@filters),- :start => start,- :rows => max,- :facets => {- :fields => @facet_fields, :limit => 20 , :mincount => 1, :sort => :count,- :queries => facet_queries- },- :highlighting => {:field_list => @text_fields})-- #TODO: call response.field_facets(??) - maybe field_facets should be return a higher level?-# logger.info({:query => query, :filter_queries => filters}.inspect)- @connection.send(request)- end-- def retrieve_field_facets(field, limit=-1, prefix=nil)- req = Solr::Request::Standard.new(:query => build_boolean_query(@queries),- :filter_queries => filter_queries(@filters),- :facets => {:fields => [field],- :mincount => 1, :limit => limit, :prefix => prefix, :missing => true, :sort => :count- },- :rows => 0- )-- results = @connection.send(req)-- results.field_facets(field)- end-- def to_s- <<-TO_S- ------- Applied facet queries: #{applied_facet_queries.inspect}- Queries: #{queries.inspect}- Filters: #{filters.inspect}- Facet queries: #{facet_queries.inspect}- ------- TO_S- end-- private- def build_boolean_query(queries)- if queries.nil? || queries.empty?- query = "*:*"- else- query = queries.collect{|q| "#{q[:negative] ? '-' : ''}(#{q[:query]})"}.join(' AND ')- end-- query- end-- def filter_queries(filters)- filters.collect do |filter|- value = filter[:value]- if value != "[* TO *]"- value = "\"#{value}\""- end- "#{filter[:negative] ? '-' : ''}#{filter[:field]}:#{value}"- end- end-end