Sha256: e7c19087ea7a02cb53e64c7f2433adbc3ff3aa2f3f68af6a5da7c75f209036b1

Contents?: true

Size: 1.54 KB

Versions: 34

Compression:

Stored size: 1.54 KB

Contents

# 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 Solr::Response::Standard < Solr::Response::Ruby
  FacetValue = Struct.new(:name, :value)
  include Enumerable
  
  def initialize(ruby_code)
    super
    @response = @data['response']
    raise "response section missing" unless @response.kind_of? Hash
  end

  def total_hits
    @response['numFound']
  end

  def start
    @response['start']
  end

  def hits
    @response['docs']
  end

  def max_score
    @response['maxScore']
  end
  
  # TODO: consider the use of json.nl parameter
  def field_facets(field)
    facets = []
    values = @data['facet_counts']['facet_fields'][field]
    Solr::Util.paired_array_each(values) do |key, value|
      facets << FacetValue.new(key, value)
    end
    
    facets
  end
  
  def highlighted(id, field)
    @data['highlighting'][id.to_s][field.to_s] rescue nil
  end
  
  # supports enumeration of hits
  # TODO revisit - should this iterate through *all* hits by re-requesting more?
  def each
    @response['docs'].each {|hit| yield hit}
  end

end

Version data entries

34 entries across 34 versions & 9 rubygems

Version Path
zigexn_solr-ruby-0.0.3 lib/solr/response/standard.rb
zigexn_solr-ruby-0.0.2 lib/solr/response/standard.rb
zigexn_solr-ruby-0.0.1 lib/solr/response/standard.rb
greglu-solr-ruby-0.0.7 lib/solr/response/standard.rb
honkster-acts_as_solr-0.1.0 lib/solr/response/standard.rb
honkster-acts_as_solr-0.2.0 lib/solr/response/standard.rb
honkster-acts_as_solr-0.2.1 lib/solr/response/standard.rb
honkster-acts_as_solr-0.2.2 lib/solr/response/standard.rb
honkster-acts_as_solr-0.2.3 lib/solr/response/standard.rb
honkster-acts_as_solr-0.2.4 lib/solr/response/standard.rb
honkster-acts_as_solr-0.2.5 lib/solr/response/standard.rb
honkster-acts_as_solr-0.3.4 lib/solr/response/standard.rb
jbasdf-acts_as_solr-0.3.3 lib/solr/response/standard.rb
jbasdf-jbasdf-acts_as_solr-0.4.0 lib/solr/response/standard.rb
jbasdf-muck-solr-0.4.0 lib/solr/response/standard.rb
jbasdf-muck-solr-0.4.1 lib/solr/response/standard.rb
jbasdf-muck-solr-0.4.2 lib/solr/response/standard.rb
onemorecloud-websolr-rails-1.1.1 lib/solr/response/standard.rb
muck-solr-3.0.1 lib/solr/response/standard.rb
muck-solr-3.0.0 lib/solr/response/standard.rb