sunspot

Exclude draft articles from Solr index with Sunspot

本小妞迷上赌 提交于 2019-12-01 07:09:52
I have an indexed model called Article and I don't want solr to index unpublished articles. class Article < ActiveRecord::Base searchable do text :title text :body end end How can I specify that article that is not #published? should not be indexed? Be sure to index the published status. class Article < ActiveRecord::Base searchable do text :title text :body boolean :is_published, :using => :published? end end Then add a filter to your query Sunspot.search(Article) do |search| search.with(:is_published, true) # ... end If you want to make sure unpublished articles are never included in the

Solr Sunspot minimum_match

落花浮王杯 提交于 2019-12-01 05:57:15
问题 I'm new to using Solr Sunspot for Rails. I'm trying to use the <filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="15" side="front"/> So naturally not all of the tokens are going to match. I can't figure out how to use the minimum_match feature in my search http://outoftime.github.com/sunspot/docs/index.html. Any help would be greatly appreciated. I tried and I just get 0 results: Articles.search do fulltext params[:q] do :minimum_match => 1 end end 回答1: You're almost

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

How to use sunspot_rails gem to search for related articles

时间秒杀一切 提交于 2019-12-01 01:55:58
I have a mini blog app and i would like user to view articles that relates to what they are reading in the article show page. without the sunspot_rails gem i would do something like this in my model def self.related_search(query, join = "AND") find(:all, :conditions => related_search_conditions(query, join)) end def self.related_search_conditions(query, join) query.split(/\s+/).map do |word| '(' + %w[name description notes].map { |col| "#{col} LIKE #{sanitize('%' + word.to_s + '%')}" }.join(' OR ') + ')' end.join(" #{join} ") end then in my view it would be like this @article.related_search

Sunspot rails: include associated models when calling .results

老子叫甜甜 提交于 2019-11-30 22:09:49
问题 Let's say that I want to search for Events in my app. When I display the results, I want to display who created the event, for instance. Is there any way to add .includes(:user) somewhere, to avoid unnecessary queries (one for each event)? I can't find it in the doc. Should I just index the user name with the event? But I'd have to keep the user info up to date... Thanks 回答1: Found the answer, it was actually quite simple: Event.search(:include => [:user]) do... 回答2: This is an updated answer

How does Sunspot modify Solr's schema.xml? Does it modify it at all?

旧时模样 提交于 2019-11-30 10:48:54
问题 Let me know if I am wrong, but I think solr only expects fields that are already mentioned in the schema.xml. So, if I have a field called 'title', I need to mention this in the schema. There is no mentioning about modifying the schema.xml in the Sunspot's documentation. I am just wondering how Sunspot modifies schema.xml allowing custom fields to be entered to the index. I also know that Sunspot uses RSolr to do things. So if there is a way to modify the schema and reload data from DB to

sunspot_rails not re-indexing model after save

北城以北 提交于 2019-11-30 02:25:32
I have a model which deploys a delayed job that updates some of its attributes. The model is declared "searchable"... searchable do text :content, :stored => true end ... which I thought would re-index after a save. On testing, this doesn't seem to be the case. If I run: rake sunspot:reindex , then everything works as expected. What could be causing this issue? As mentioned by Jason, you can call Sunspot.commit_if_dirty to issue a commit from your client. From the server configuration side, another approach would be to set the autoCommit property in your solrconfig.xml to automatically issue

rake sunspot:reindex rake aborted! RSolr::Error::Http - 404 Not Found

丶灬走出姿态 提交于 2019-11-29 22:54:11
问题 I can no longer reindex and cannot resolve this issue. Spend several hours digging the web for this issue. ** *regarding production environment * development goes ok. :( How would one fix this? rake sunspot:reindex rake aborted! RSolr::Error::Http - 404 Not Found Error: Not Found Request Data: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><query>type:Match</query></delete>" Backtrace: /srv/books/shared/bundle/ruby/2.0.0/gems/rsolr-1.0.9/lib/rsolr/client.rb:268:in `adapt_response' /srv

How does Sunspot modify Solr's schema.xml? Does it modify it at all?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 22:30:33
Let me know if I am wrong, but I think solr only expects fields that are already mentioned in the schema.xml. So, if I have a field called 'title', I need to mention this in the schema. There is no mentioning about modifying the schema.xml in the Sunspot's documentation. I am just wondering how Sunspot modifies schema.xml allowing custom fields to be entered to the index. I also know that Sunspot uses RSolr to do things. So if there is a way to modify the schema and reload data from DB to Solr using RSolr, please let me know. As karmajunkie alludes to, Sunspot uses its own standard schema. I