Paste number 43855: search_controller.rb

Paste number 43855: search_controller.rb
Pasted by: rsinger
When:2 years, 1 day ago
Share:Tweet this! | http://paste.lisp.org/+XU7
Channel:#code4lib
Paste contents:
Raw Source | XML | Display As
require 'enumerator'
class SearchController < ApplicationController
  layout "layouts/search_standard"
  def facet
    index = Index.new
    facets = params[:facets].split("~")
    start = (((params[:page]||1).to_i*25)-25)   
    facet_query = ''
    @facets = []
    while facets.length > 0
      key = facets[0]
      val = facets[1]      
      facet_query << ' +'+key.to_s+':"'+val.to_s+'"'
      @facets << key+'~'+val
      facets.delete_at(0)
      facets.delete_at(0)      
    end
    @query = params[:query]+facet_query
    @results = index.conn.query(@query, {:start=>start,:operator=>:and, :rows=>25,:highlighting=>{:field_list=>["title","data","creator_str"]}, :facets=>{:fields=>["item_type","form_str","topic_str"],:mincount=>1, :limit=>11}})    
    @pages = pages_for(@results.data["response"]["numFound"])    
    @records = []
    @results.data["response"]["docs"].each do | doc |
      record = Kernel.const_get(doc["record_class"]).new    
      @records << record.build_from_solr(doc, @results.data["highlighting"][doc["id"]])
    end    
  end 
  
  def index
    index = Index.new
    start = (((params[:page]||1).to_i*25)-25)
    @facets = []
    @results = index.conn.query(params[:query], {:start=>(start), :operator=>:and, :rows=>25,:highlighting=>{:field_list=>["title","data","creator_str"]}, :facets=>{:fields=>["item_type","form_str","topic_str"],:mincount=>1, :limit=>11}})    
    @pages = pages_for(@results.data["response"]["numFound"])
    @records = []
    @results.data["response"]["docs"].each do | doc |
      record = Kernel.const_get(doc["record_class"]).new
      @records << record.build_from_solr(doc, @results.data["highlighting"][doc["id"]])
    end
  end  
end

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.