Skip to content

Instantly share code, notes, and snippets.

@robdimarco
Created December 29, 2011 21:41
Show Gist options
  • Save robdimarco/1536342 to your computer and use it in GitHub Desktop.
Save robdimarco/1536342 to your computer and use it in GitHub Desktop.
Simple Business class with a text and a location
class Business < ActiveRecord
searchable do
text :name # Will be stored as a field named name_text in Solr
text :location # Will be stored as a field named location_text in Solr
end
end
# Given data set
# ID Name Location
# 1 Boone Moving Service Raleigh, NC
# 2 Bone’s Moving New York, NY
# 3 Boone Moving Los Angeles, CA
# 4 Jimmy’s Movers Boone, NC
#
# this query will match records 1 & 3
#
# > Sunspot.index!(Business.all)
# > search = Business.search{keywords "Boone Moving"}
# > puts search.results.map(&:id)
#[1,3]
<!-- Pertinent schema.xml configuration -->
<fieldType name="text" class="solr.TextField" omitNorms="false">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
<!-- ... -->
<dynamicField name="*_text" stored="false" type="text" multiValued="true" indexed="true"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment