Integrates directly into ActiveRecord models and allows specifying which attributes we need The need for a new library was apparent, so the Sunspot was born. To define which Rails models should be searchable and how the indexes will be updated. However RSolr is still rather low-level and does not provide any DSL or convenience methods.Solr HTTP API that allows interacting with Solr from Ruby. Nobody wants to mess with raw XML over HTTP, so here enters RSolr – a wrapper around the.The only way you can communicate directly with Solr from a Rails application yet hard to learn full-text search solution.It is generally considered a robust and full-featured Solr – a Java server that runs as a separate service and communicates.We’ll be using sunspot – an excellent gem thatĪdds a nice DSL (really, it’s nice) on top of rsolr.Īt this point you might be asking: “Wait! What’s RSolr? I’m now totally confused between Solr, RSolr and Sunspot and how they relate to each other”. Let’s take a little detour and speak about Solr and the gems that enable it in Rails. We must remove people who have our search term in their dislikes attribute.įor example if a person dislikes Chinese couisine, and we’re searching for people We should allow limiting the search radius, specify the search term and see the results. Next part is where the fun starts: we need to be able to search for other users nearby. The system and current_user.id is stored in the encrypted cookie. Now when we go back to the browser and reload the page we can enter the profile data,Īllow the browser to get our geolocation and click save. # app/models/person.rb class Person < ActiveRecord : :Base validates :name, :about, :likes, :dislikes, presence : true end The view code checks the current_user method to see if the current user profile has been filled. I remove them all and leave the application.js empty. We now need to modify the app/assets/javascripts/application.js If this is a new user, he fills his details, optionally allows a browser to get his location and He can use the search form and search for people nearby. This UI has two parts: if a user has already filled his details, Allow browser to access your location if you want to be found by people near you. Hello, Search people near you: Search within mile radius: Hello, guest Fill your profile so that people could find you. The point is to make a small but complete application in a single articleĪnd it is possible to do so only by keeping it really simple.ġ 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 I’ll be using long views and JavaScript inside ERB templates. Not create an ideal rails application structure. Overcome the feeling of uncomfortable uneasiness when thinking about full text search technology.ĭisclaimer: My goal here is to familiarize the reader with full-text search, I’ll build a simple people near me application using Solr in small incremental steps and hopefully help readers to This article assumes you’re comfortable with Ruby, Rails and PostgreSQL. I was one of those developers who never used full-text search,īut I have changed and I invite others to join me and discover However, most developers search with SQL and relational databases.Īlmost every developer knows deep inside that full-text search is better suited for searching text, but continues to use old LIKE '%?%' queries. Every developer has heard of full-text search.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |