Sha256: 699ca4c328b2f3530128bc50bd19cb79a1aa98de662c6918a9eeaf8b1d5fbd87

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

=RSolr::Ext
A set of helper methods/modules to assist in building Solr queries and handling responses when using the RSolr library.

==Request Example
  solr_params = RSolr::Ext.map_params(
    :page=>2,
    :per_page=>10,
    :phrases=>{:name=>'This is a phrase'},
    :filters=>['test', {:price=>(1..10)}],
    :phrase_filters=>{:manu=>['Apple']},
    :queries=>'ipod',
    :facets=>{:fields=>['cat', 'blah']}
  )
  
  rsolr = RSolr.connect
  
  response = rsolr.select(solr_params)

==Response Example
  rsolr = RSolr.connect
  
  raw_response = rsolr.select(:q=>'*:*)
  r = RSolr::Ext::wrap_response(raw_response)
  
  r.ok?
  r.params
  r.docs
  r.docs.previous_page
  r.docs.next_page
  r.facets

You can access values in the response hash using symbols or strings.

===Doc Pagination
After creating a RSolr::Ext::Response object, pass-in the response.docs to the will_paginate view helper:
  rsolr = RSolr.connect
  raw_response = rsolr.select(:q=>'*:*)
  @response = RSolr::Ext.wrap_response(raw_response)
  # in view:
  <%= will_paginate @response.docs %>

==The Findable Module

You can get a modified RSolr.connect object by calling RSolr::Ext.connect.

The object returned is an RSolr::Connection::Adapter (Direct or HTTP) with additional methods attached, most notably #find, which comes from the RSolr::Ext::Findable module.

The #find method provides a convenient way to search solr. Here are some examples:
  
  solr = RSolr::Ext.connect
  
  # q=jefferson - returns all docs
  all_jefferson_docs = solr.find 'jefferson'
  
  # q=jefferson&rows=1 -- first doc only
  a_single_jefferson_doc = solr.find :first, 'jefferson'
  
  # q=jefferson&fq=type:"book" - all docs
  books_about_jefferson = solr.find 'jefferson', :phrase_filters=>{:type=>'book'}
  
  # q=something -- the entire response
  solr_response = solr.find {:q=>'something'}, :include_response=>true

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mwmitchell-rsolr-ext-0.7.1 README.rdoc
mwmitchell-rsolr-ext-0.7.5 README.rdoc