sunspot-rails

Rails 4: RSolr::Error::Http (RSolr::Error::Http - 404 Not Found

眉间皱痕 提交于 2019-12-04 18:54:07
问题 I am in the process of upgrading my app to Rails 4, and now got my rails server, as well as sunspot solr, after a lot of tinkering, to run, I can access Solr admin page. However when I try to access solr from my rails development app to do search or index, I get the following error RSolr::Error::Http (RSolr::Error::Http - 404 Not Found Error: Not Found Request Data: "fq=type%3AMatch&fq=date_in_utc_d%3A%7B2013%5C-11%5C-29T21%5C%3A00%5C%3A00Z+TO+%2A%7D&fq=approval__s%3AAPPROVED&sort=date_d+asc

How to do simple boolean query in sunspot solr

青春壹個敷衍的年華 提交于 2019-12-04 15:22:49
问题 >>> marketing = User.search do |s| >>> s.fulltext "Marketing" >>> end >>> marketing.total 1448 >>> sales = User.search do |s| >>> s.fulltext "Sales" >>> end >>> sales.total 567 >>> marketing_and_sales = User.search do |s| >>> s.fulltext "Marketing AND Sales" >>> end >>> marketing_and_sales.total 945 >>> marketing_or_sales = User.search do |s| >>> s.fulltext "Marketing OR Sales" >>> end >>> marketing_or_sales.total 945 <Sunspot::Search:{:fq=>["type:User"], :q=>"Marketing AND Sales", :fl=>"*

sunspot solr how to search multiple models correctly? All examples online fail

久未见 提交于 2019-12-03 15:22:09
How would one correctly search multiple models in SunSpot Solr? Profile model has_one :match searchable do string :country string :state string :city end Match model belongs_to :profile searchable do string :looking_for_education integer :age_from integer :age_to end ProfilesController#Index def index @search = Sunspot.search Profile, Match do with(:country, params[:country]) with(:state, params[:state]) with(:looking_for_education, params[:looking_for_education]) <= from the 2nd model end @profiles = @search.results end This fails with: Using a with statement like with(:age).between(params[

Querying multiple models with different attributes using Sunspot

怎甘沉沦 提交于 2019-12-03 09:56:51
问题 I'm using Sunspot to index and search several models in a Rails project and I need to limit results based on the models' HABTM associations with a Department model. This is because users may not have permission to see records in all departments so results from those departments shouldn't be returned. Here are the important parts of two of the models: class Message < ActiveRecord::Base has_many :comments, dependent: :destroy has_and_belongs_to_many :departments searchable do text :title, :body

Querying multiple models with different attributes using Sunspot

北战南征 提交于 2019-12-03 00:28:07
I'm using Sunspot to index and search several models in a Rails project and I need to limit results based on the models' HABTM associations with a Department model. This is because users may not have permission to see records in all departments so results from those departments shouldn't be returned. Here are the important parts of two of the models: class Message < ActiveRecord::Base has_many :comments, dependent: :destroy has_and_belongs_to_many :departments searchable do text :title, :body text :comments do comments.map(&:body) end date :created_at integer :department_ids, using:

sunspot solr undefined field type

血红的双手。 提交于 2019-12-02 04:06:19
问题 I'm having a problem with my sunspot and solr. In development it worked like charme but in production I get the following error out of my rails production log: RSolr::RequestError (Solr Response: undefined field type): app/controllers/search_controller.rb:7:in `index' I guess it has something to do with the schema.xml. But I'm quite new to solr. So can anybody help me? OK: Controller def index unless params[:q].blank? @search = Question.search do fulltext params[:q] end @results = @search

Sunspot `LIKE` query

一笑奈何 提交于 2019-12-01 11:37:42
I'm using sunspot . How can I run a LIKE query ( LIKE %q% )? I would like to do something like this: @search = Sunspot.search(User) do |q| q.text_fields { with(:company_name).like(params[:q]) } end.results instead of: @search = Sunspot.search(User) do |q| q.text_fields { with(:company_name).starting_with(params[:q]) } end.results which partially works for me. Reviewing the sunspot code, I found this piece of code: class StartingWith < Base private def to_solr_conditional "#{solr_value(@value)}*" end end It basically generates the following sunspot search hash: Sunspot.search(User) do |q| q

Sunspot `LIKE` query

五迷三道 提交于 2019-12-01 09:36:05
问题 I'm using sunspot . How can I run a LIKE query ( LIKE %q% )? I would like to do something like this: @search = Sunspot.search(User) do |q| q.text_fields { with(:company_name).like(params[:q]) } end.results instead of: @search = Sunspot.search(User) do |q| q.text_fields { with(:company_name).starting_with(params[:q]) } end.results which partially works for me. Reviewing the sunspot code, I found this piece of code: class StartingWith < Base private def to_solr_conditional "#{solr_value(@value)

View raw Solr tokens for a single field on a single document

﹥>﹥吖頭↗ 提交于 2019-12-01 05:19:06
I'm debugging my Solr schema and I'd like to see the results of tokenizing a specific field. For a simplified example, if I have: <fieldType name="text" class="solr.TextField" omitNorms="false"> <analyzer> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.StandardFilterFactory"/> <filter class="solr.LowerCaseFilterFactory"/> <filter class="solr.PorterStemFilterFactory"/> <filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="15" side="front"/> </analyzer> </fieldType> and I indexed a field with the value "Hello, worlds!" , I want to see something along

View raw Solr tokens for a single field on a single document

喜你入骨 提交于 2019-12-01 02:12:56
问题 I'm debugging my Solr schema and I'd like to see the results of tokenizing a specific field. For a simplified example, if I have: <fieldType name="text" class="solr.TextField" omitNorms="false"> <analyzer> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.StandardFilterFactory"/> <filter class="solr.LowerCaseFilterFactory"/> <filter class="solr.PorterStemFilterFactory"/> <filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="15" side="front"/> </analyzer