Using POST instead of GET for long queries in Sunspot / Solr - ruby-on-rails

I need to run a long query over Solr but Sunspot is using GET as the default method. I know that this is something supported on RSolr, but i don't know if i can do it through Susnpot.
Thanks!

According to the Sunspot source on GitHub, Sunspot already uses POST as the default for submitting queries to Solr when searching. This was changed in 2011, so if you have a VERY old version of Sunspot, that might be an issue.
Otherwise if you're still seeing GETs on the server side, it'd be helpful to see the code you're actually using for searching.

Related

Heroku Rails Websolr, sunspot is not free in production?

I've added sunspot gem in my application and tried to send it to production in heroku, but I'm trying to reindex my database, however, I'm getting an error. I did some more digging and I think I have to add websolr as an add-on? This costs $20/month. Is this the only option?
THanks
Founder of Websolr + Bonsai here (Heroku addons for Solr and Elasticsearch).
Rich's answer is pretty solid, with the exception of the SQL LIKE operator, which I do not recommend. The performance does not scale, and you're either going to sink in a lot more time than you might expect in order to eke out baseline search functionality. End result: a lot of time spent, and unhappy users.
Postgres full text search is a reasonable alternative, though the term analysis and result ranking will be lacking compared to Solr/Elasticsearch as your search traffic starts to grow in production.
You might also consider our sister service, Bonsai, which does offer a free Starter plan. It uses Elasticsearch, which means you'd want to use the official Ruby bindings for Elasticsearch rather than Sunspot.
Lastly, if you already have a production app on Heroku, you are welcome to create more than one index in your account, and share those indexes with your staging/qa and other apps.
I've done some more research and found out that there are other options if you don't want to take the websolr path. These other answers are good for some insights, but doesn't give an alternative to what can be used.
For some that's still looking, I suggest taking a look at Elastic Search
Rails Cast has a good tutorial on this as well.
And to use it with heroku, look into Bonsai which gives users a free option.
Hopefully this answer will help those that are also seeking other options than using sunspot gem with solr
Solr on Heroku uses their own add-on, which starts at $20pm:
Although I don't know why it costs up front, and doesn't have a "trial" option like many of the other Heroku Add-ons, there are certain ways around it
Full Text Search
Full text search is what you're performing, and Solr is a tool to make the process much more efficient. Despite being quite DB-expensive, you can use full text searching with Heroku, depending on your DB:
MYSQL
To perform full-text searching on MYSQL, you can simply use the "LIKE" operator with %variable% as your search phrase, like this:
SELECT * FROM `table` WHERE `name` LIKE `%benjamin%`
This basically finds all the records where the name column contains "benjamin" somewhere inside it. This is quite slow
POSTGRESQL
PostgreSQL offers more power in its full text searching, but is nonetheless still quite slow & expensive. You can read more about it here, but with rails, you can use a bunch of gems which do the task for you
We recently used a gem called textacular here: http://firststop.herokuapp.com
Here is the code we used for it:
#Search
def self.search(search)
basic_search(name: search, description: search)
end
Further Reading
You can see how full text searching works here: Any reason not use PostgreSQL's built-in full text search on Heroku?
I would recommend if you're just getting the foundations established for your app. Afterwards, you can upgrade to a more dedicated solution in the form of Solr et al
Here are
If you want to use the Heroku platform it starts for free, but you have to pay for almost every add-on, extra workers, extra storage, search engine, background tasks, you name it.
For $20/month you could also get a decent VPS, but you would have to install and manage that server by yourself.
As for sunspot/solr on Heroku, I don't think you can do that for free.

Grails and Solr

I'm doing this project, in which i need to create a more powerfull GUI for apache solr https://lucene.apache.org/solr. I'm doing it with Grails, and basically, I just need to create a GUI which will manipulate solr url's and get me the results I need. The way im seing this, I can have my project Grails running at same time as Solr, nothing new here. But I would like to do it, but only have 1 server running. Is there any way to do this with Grails?
This may be a bit late, but in case it helps someone else I'm adding my $.02.
Look at SolrJ for the java API to communicate from grails/groovy/java to a separate solr instance. It's quite easy, and once you get your head wrapped around using Solr's NamedLists for response info, you should have no trouble.
Mats Lindh has some further information on solrj:
http://e-mats.org/2008/04/using-solrj-a-short-guide-to-getting-started-with-solrj/
The Solr plugin embeds an instance of Solr - http://www.grails.org/plugin/solr - This might not be the best way for production, but it might be a good place to start.

Is it possible to use DataImportHandler in Sunspot Rails?

I have a rails app which has data in MySQL db. I am using Sunspot to interact with Solr and I would like to be able to use DataImportHandler to import data from MySQL to Solr. I have tried searching on google and I can't seem to find an answer to my question.
Ultimately, I want to be able to create a rake task that will do this data import.
The idea is interesting, but the answer is no. You would have to create your own custom data-config.xml. That said, so long as you stick to Sunspot field naming conventions, you should still be able to use Sunspot for searching with such a setup.
Generation of that data-config.xml from Sunspot's configuration would definitely be an interesting addition. Maybe for a future version.

Solr sunspot in different environments

So I have been using solr sunspot for a couple of days and have been going a little crazy over an issue with it. I have search many different sites for the answer, but a lot of people seem to have different ideas. I am trying to figure out how sunspot manages indexing/reindexing of models in different environments with auto indexing on. This is what I have concluded:
Dev/Prod: Saving/updating an object automatically updates the indexing of that object in solr
Test: Saving/updating an object does not automatically update the index and you need to call object.reindex! in order for it to take effect.
Console: Same as testing. Reindex is required to properly update solr.
So does this look correct? It was killing me for so long whether something was wrong with my solr sunspot setup or if it just doesn't work the same in these different environments. Any help would be greatly appreciated!
After updating a document in Solr, you must issue a "commit" to tell Solr to write the changes to disk and have them start appearing in search results. Sunspot::Rails takes care of this automatically in the course of a Rails request, but outside of that (in tests, from the console), you need to do it explicitly. It's a simple Sunspot.commit.
There are three main ways to update an index:
object.index: marks the object for indexing, but might not be immediately indexed
object.index!: indexes the object immediately
Class.reindex: indexes all objects on the model immediately
It sounds like you should be using the .index! method instead of the .index method on console.

Are there other search options for heroku

I am about to launch a beta site, and heroku looks like a great option. The only think that is getting me down is that the only search option is $20/mth for the Websolr add-on.
I am sure that Websolr is great, but at this very early point in this project, I rather not light up that expense.
Are there any free search options to couple with heroku's Blossom (free) plan.
I feel like such a cheapskate!
This post seems to have good options:
Leveraging the full text search of postgrSQL:
http://tenderlovemaking.com/2009/10/17/full-text-search-on-heroku.html
Also explains the options of Ferret and Solr.
IndexTank has a heroku addon you can use for free.
It has some advantages over websolr, like realtimeness, fast (all in ram), and a very flexible scoring system that doesn't require to reindex (allows for very easy a/b testing).
My gem pg_search does full-text search against PostgreSQL, and works directly on Heroku.
Check it out and let me know if it works for you!
acts_as_tsearch works great. No configuration needed if you have postgresql > 8.3. Have to experiment with multiple tables though. Will use it on heroku till i can afford the WebSolr Add-on. I found it a better option compared to the texticle method as explained in the article link above (tendermaking).
acts_as_tsearch: http://github.com/pka/acts_as_tsearch
No, I was looking for that too a week ago, and didn't find anything...
And I don't think there is any work in progress on another add-ons like this as they already have one, so they won't put another that is free... :/
Anyway, heroku is amazing, so try to make it work with code or just spend $20 :)
acts_as_ferret won't work as Heroku cleans up the /tmp directory regularly. Even i am in need of a full-text solution. Thinking of trying out the acts_as_tsearch plugin.
Looks like IndexTank was purchased by LinkedIn and will be discontinuing support (although some portions might be open-sourced in the future). See this post for more info: https://indextank.com/documentation/faq2
If you're using Postgres for your Rails app then take a look at this free way to do full text search:
Part 1 and
Part 2
This uses the pg_search gem to allow you to use PostgreSQL's pg_search_scopes feature and have full text search without any other dependencies.

Resources