sunspot-rails

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

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

sunspot_rails not re-indexing model after save

梦想的初衷 提交于 2019-11-28 22:48:47
问题 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? 回答1: As mentioned by Jason, you can call Sunspot.commit_if_dirty to issue a commit from your client. From the server configuration

SocketError (getaddrinfo: Name or service not known) - Sunspot/Solr Rails development

回眸只為那壹抹淺笑 提交于 2019-11-27 15:00:53
问题 I have had lots of trouble with deploying my rails 3.0.10 application to Ubuntu 10.04 server with Passenger, Capistrano, nginx and MySQL (and even more trouble with apache2). After downgrading rake to 0.8.7 it's finally working, but now Sunspot/Solr doesn't work in my development environment. The sunspot_solr server is running, and I am able to get the server's url, and connect to it via the browser. The url is the same as in sunspot.yml. I have no idea what I have done that can have caused