Skip to content

Instantly share code, notes, and snippets.

@scottburton11
Created January 11, 2011 20:47
Show Gist options
  • Select an option

  • Save scottburton11/775105 to your computer and use it in GitHub Desktop.

Select an option

Save scottburton11/775105 to your computer and use it in GitHub Desktop.
require 'mongoid'
require 'sunspot'
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db("geo_near_with_boost")
end
class Hoobatz
include Mongoid::Document
field :name
field :score
field :coordinates, :type => Array
def self.search(query)
Sunspot.search Hoobatz do
fulltext query do
boost 10 do
with(:name, "Horkins")
end
end
with(:coordinates).near(34.0661071, -118.3841777)
end
end
end
module Adapters
class InstanceAdapter < Sunspot::Adapters::InstanceAdapter
def id
@instance.id
end
end
class DataAccessor < Sunspot::Adapters::DataAccessor
def load(id)
@clazz.find(id)
end
end
end
Sunspot::Adapters::InstanceAdapter.register(Adapters::InstanceAdapter, Hoobatz)
Sunspot::Adapters::DataAccessor.register(Adapters::DataAccessor, Hoobatz)
Sunspot.setup Hoobatz do
text :name
string :name
integer :score
location :coordinates do
Sunspot::Util::Coordinates.new(coordinates[0], coordinates[1])
end
end
ruby-1.9.2-p0 :001 > Hoobatz.search("Horkins")
RSolr::RequestError: Solr Response: orgapachelucenequeryParserParseException_Cannot_parse__query_dismax_qfname_text_bqname_sHorkins10Horkins_coordinates_s9q5cf1e32wxh10_OR_coordinates_s9q5cf1e32wx00625_OR_coordinates_s9q5cf1e32w000391_OR_coordinates_s9q5cf1e320000244_OR_coordinates_s9q5cf1e300000153_OR_coordinates_s9q5cf1e0000000954_Missing_end_quote_for_string_at_pos_27_strdismax_qfname_text_bq
from /Users/scott/.rvm/gems/ruby-1.9.2-p0/gems/rsolr-0.12.1/lib/rsolr/connection/requestable.rb:39:in `request'
from /Users/scott/.rvm/gems/ruby-1.9.2-p0/gems/rsolr-0.12.1/lib/rsolr/client.rb:34:in `request'
from /Users/scott/.rvm/gems/ruby-1.9.2-p0/gems/sunspot-1.2.1/lib/sunspot/search/abstract_search.rb:35:in `execute'
from /Users/scott/.rvm/gems/ruby-1.9.2-p0/gems/sunspot-1.2.1/lib/sunspot/session.rb:59:in `search'
from /Users/scott/.rvm/gems/ruby-1.9.2-p0/gems/sunspot-1.2.1/lib/sunspot.rb:335:in `search'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment