Working with an existing Solr index in RoR - ruby-on-rails

I'm writing a Ruby on Rails app that would replace an old application. We have an existing Solr service running which I wish to integrate in our new RoR app. What is the best way to approach this? From what I've learned so far online, Sunspot is more suitable for automatically indexing Ruby object in Solr not the other way around (integrating an already existing index) ?!

you can check upon rsolr, on which sunspot is based upon, which will allow you to query on an existing index.

Related

Neo4j with Ruby On Rails

I created a ruby on rails web app which I deployed on heroku, by following this guide
http://ruby.railstutorial.org/ruby-on-rails-tutorial-book
The app is very similar to this tutorial in that a user can create an account, log in, create an object with some information which is belongs to that user. These objects I created are meant to represent nodes which I would like to be able to create relationships between.
I have been reading up on Neo4j and it seems like the best fit for ruby but then I read that it only really works with JRuby. Could anyone tell me would it work with my implementation and if so , how? or if it dosent, what should I use instead?
JRuby allows Ruby to access Neo4j directly through the Java API. It is the fastest implementation possible. However, Neo4j also provides a REST API that allows any language to access it over HTTP.
I seems like your answer may be here: Which Ruby REST API client for neo4j?
This is again using the Neography gem, but this blog maxdemarzi has got some really nice posts on integrating ruby with neo4j.
Here's a link: http://maxdemarzi.com/2012/01/04/getting-started-with-ruby-and-neo4j/
But as mentioned by others, I don't think you'd get anything that can talk directly to the Java API other than JRuby.

Schemaless design for Ember data in Ember.js

We are having schemaless database on MongoDB in Rails. I want to know how to use such a schemaless emberjs data design to integrate with such a design.
I am not able to find any documentation on if this can be achieved or if there is any best practice
Can any one help me with this ?
EDIT:
Question is on how to use EmberJS persistent datastore for a schemaless MongoDB Rails backend.
The first two links below should help. See how the first link is setting primaryKey: '_id' to recognize mongodb _id and the second link shows how to make active_model_serializer gem work with mongoid, the gem is ember-core team's recommended gem for working with rails and ember-data :
https://github.com/dagda1/workoutzenith/tree/master/app/models
https://github.com/dagda1/workoutzenith/blob/master/config/initializers/active_model_serializer_mongoid_initializer.rb
If you run into problems with embedded mongodb documents and ember-data, this should solve it:
Ember-data embedded objects stored as separate objects
Read the link below and also examine the github project:
http://tardate.blogspot.co.uk/2012/03/rails-ember-mongodb-bootstrap.html
https://github.com/evendis/rails-ember-mongo-bootstrap-demo
This is not using rails but nodejs, mongodb and emberjs. The mongodb + emberjs might still be useful to you
https://github.com/abelaska/nodejs-emberjs-mongodb
There is still no clear and scalable solution I see of how to apply Ember to scenario where the Rails backend database like MongoDB stores document of any depth with unknown fields.
There are some ways of normalizing but still with existing REST/REST+DS we may have to write a lot of code to serialize and de serialize.
Take a peek on the discussions:
https://github.com/emberjs/data/issues/53#issuecomment-9196555
https://github.com/emberjs/data/issues/100
If some one finds a better pick, please share with me.
Jus follow the links http://robert-reiz.com/2012/03/05/rails-mongodb-tutorial/, http://www.mongodb.org/display/DOCS/Rails+3+-+Getting+Started

Advice needed to full text searching on mongoid

I've a mongoid embedded one to many model on Rails 3.1, to full text search within. I neet something very light and simple to deploy on heroku too, without having to pay for add-ons, initially.
All heroku Full-Text Search add-on currently, seem to have just paying plans (which is no good to start with), see Flying Sphinx and Websolr.
I need advice on a good solution (a ruby gem deployable on heroku) to start with and than to scale to other cloud services eventually.
Maybe MongoDB's core functionalities are enough for your needs:
http://www.mongodb.org/display/DOCS/Full+Text+Search+in+Mongo
There are two more possibilities that come into my mind:
1) you can use this gem:
https://github.com/mauriciozaffari/mongoid_search
2) you can use elasticsearch (http://www.elasticsearch.org/) and use the following gem:
https://github.com/karmi/tire
However, you couldnt use this solution with heroku only, you would have to setup your own server, for which in the case you want to use heroku, EC2 would be recommendable
We were using the sunspot_mongo gem with solr on Mongoid 2.4.
But after upgrading to Mongoid 3, support for sunspot seems to not be there. So we're investigating a move to elasticsearch with the tire gem. There are some new offerings in the "search as a service space" for elasticsearch, but they don't seem quite production ready yet, so hoping that changes quickly.
Hope it helps!

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.

How do I do full-text searching in Ruby on Rails?

I would like to do full-text searching of data in my Ruby on Rails application. What options exist?
There are several options available and each have different strengths and weaknesses. If you would like to add full-text searching, it would be prudent to investigate each a little bit and try them out to see how well it works for you in your environment.
MySQL has built-in support for full-text searching. It has online support meaning that when new records are added to the database, they are automatically indexed and will be available in the search results. The documentation has more details.
acts_as_tsearch offers a wrapper for similar built-in functionality for recent versions of PostgreSQL
For other databases you will have to use other software.
Lucene is a popular search provider written in Java. You can use Lucene through its search server Solr with Rails using acts_as_solr.
If you don't want to use Java, there is a port of Lucene to Ruby called Ferret. Support for Rails is added using the acts_as_ferret plugin.
Xapian is another good option and is supported in Rails using the acts_as_xapian plugin.
Finally, my preferred choice is Sphinx using the Ultrasphinx plugin. It is extremely fast and has many options on how to index and search your databases, but is no longer being actively maintained.
Another plugin for Sphinx is Thinking Sphinx which has a lot of positive feedback. It is a little easier to get started using Thinking Sphinx than Ultrasphinx. I would suggest investigating both plugins to determine which fits better with your project.
I can recommend Sphinx. Ryan Bates has a great screencast on using the Thinking Sphinx plugin to create a full-text search solution.
You can use Ferret (which is Lucene written in Ruby). It integrates seamless with Rails using the acts_as_ferret mixin. Take a look at "How to Integrate Ferret With Rails". A alternative is Sphinx.
Two main options, depending on what you're after.
1) Full Text Indexing and MATCH() AGAINST().
If you're just looking to do a fast search against a few text columns in your table, you can simply use a full text index of those columns and use MATCH() AGAINST() in your queries.
Create the full text index in a migration file:
add_index :table, :column, type: :fulltext
Query using that index:
where( "MATCH( column ) AGAINST( ? )", term )
2) ElasticSearch and Searchkick
If you're looking for a full blown search indexing solution that allows you to search for any column in any of your records while still being lightning quick, take a look at ElasticSearch and Searchkick.
ElasticSearch is the indexing and search engine.
Searchkick is the integration library with Rails that makes it very easy to index your records and search them.
Searchkick's README does a fantastic job at explaining how to get up and running and to fine tune your setup, but here is a little snippet:
Install and start ElasticSearch.
brew install elasticsearch
brew services start elasticsearch
Add searchkick gem to your bundle:
bundle add searchkick --strict
The --strict option just tells Bundler to use an exact version in your Gemfile, which I highly recommend.
Add searchkick to a model you want to index:
class MyModel < ApplicationRecord
searchkick
end
Index your records.
MyModel.reindex
Search your index.
matching_records = MyModel.search( "term" )
I've been compiling a list of the various Ruby on Rails search options in this other question. I'm not sure how, or if to combine our questions.
It depends on what database you are using. I would recommend using Solr as it offers up a lot of nice options. The downside is you have to run a separate process for it. I have used Ferret as well, but found it to be less stable in terms of multi-threaded access to the index. I haven't tried Sphinx because it only works with MySQL and Postgres.
Just a note for future reference: Ultra Sphinx is no longer being maintained. Thinking sphinx is its replacement. Although it lacks several features at this time like excerpting which Ultra sphinx had, it makes up for it in other features.
I would recommend acts_as_ferret as I am using it for Scrumpad project at work. The indexing can be done as a separate process which ensures that while re-indexing we can still use our application. This can reduce the downtime of website. Also the searching is much faster. You can search through multiple model at a time and have your results sorted out by the fields you prefer.

Resources