Reputation: 233
How can I match 2 sentences from a database to retrieve those that match the most?
For example there are three users (user_1, user_2, user_3).
user_1 inserts into the database a description such as:
"Batman Begins is a 2005 British-American superhero film based on the fictional DC Comics character Batman, co-written and directed by Christopher Nolan. It stars Christian Bale as Batman along with Michael Caine, Liam Neeson, Katie Holmes, Gary Oldman, and Morgan Freeman." (from wiki)
user_2 then inserts into a different database a description for a movie: "batman movies based on comics"
user_3 inserts: "Robin Hood is a 2010 British-American epic adventure film based on the Robin Hood legend, directed by Ridley Scott and starring Russell Crowe and Cate Blanchett." (from wiki)
and the algorithm returns that user_1's and user_2's description match.
I am using ruby version 2.0.0 and rails 4.0.4
If you could direct me to any appropriate algorithm/gem that would be great.
Upvotes: 0
Views: 104
Reputation: 175
You should try adding a search engine like gem for your rails application. Some options to look at are ThinkingSphinx, SearchKick, or SunSpot. https://www.ruby-toolbox.com/categories/rails_search is a good place to do some more research about which will would be an appropriate gem for you.
Upvotes: 1
Reputation: 6076
What you are describing is full text search. Ace listed some gems that implement it. But if your application is basic then you can just do it in the database. Postgres and Mysql have functionality built in. Even Sqlite has an extension for implementing it. So in the language of full text search, user_1 and user_3 entered documents and user_2 entered a query. Here is a link to a blog post describing how to do this using Rails 4 and Postgres: https://coderwall.com/p/vngr0a
Upvotes: 0