Can anyone recommend a gem for searching that actually allows me to easily filter my results in ruby on rails? - ruby-on-rails

I've tried thinking sphinx after being pointed in that direction and simple filtering seems impossible. I've googled and asked questions for 2 days now and it seems it can't be done which is shocking because it's something commonly done when searching on websites.
All I would like to do add filtering options to my search form such as filtering by one or a combination of:
When user hits browse page all the sites users are returned but showing 20 results per page
Filtering options
in: location
who are: sexual preference
between the ages: age range
and located in: country
My search page works fine because all I require is 1 textfield a user uses for finding users by email, username or full name. My browse page is a different story because I'm using 1 form with multiple text fields and one or two select fields.
Example
Is there a gem that does this easily and performs well at the same time?
or would doing this manually via find methods be the only way?
Kind regards

Apart from using Sphinx and Thinking Sphinx, you can think of those gems: meta_where and meta_search
However after reading your description I think Sphinx is the best choice here indeed.
You wrote that it seems impossible to apply simple filtering using Thinking Sphinx. Let me explain a bit of Thinking Sphinx within the post you mentioned under the link: Example

You can go for Elasticsearch. Ruby has the 'Tire' gem, which is a client for ElasticSearch http://www.elasticsearch.org/

Related

Best solution for clickable search list in Rails

I'm developing an app in Rails with a nutrient database. Now I'm looking for an easy solution for users to search the database through a search field, which as they type will present a list of records from the database, which at the same time are clickable and once clicked will direct them directly to the show path of that nutrient.
I'm thinking of something like this. If you enter e. g. "burger" it does exactly what I need.
I've been researching now for some days and found solutions from jQuery autocomplete to Elasticsearch to typeahead.js but now I'm totally lost, which solution would be the right one for my usecase (I tried jQuery autocomplete but at the end it turned out that this is not exactly what I need).
Anybody some ideas?
Thanks.
Algolia is a well known solution for instant search, but not the easiest one to implement (though their support team is incredible).
You should look into searchkick which is based on elasticsearch, and has an instant search feature.
It is relatively easy to implement, and pretty well documented.

Advice with Full Text Search Engine in Rails

I am trying to add to my website a search bar like the one on Facebook. I want my users to be able to search through my products, my other users ... But I also want the result to be displayed in real time without pressing a button. I am currently looking at several options (thinking-sphinx, ferret, ...) but I am not sure which one to use and that's why I would like to get advices from pros ;)
So my requirement are :
Result to be displayed in real-time in a box on the current page.
Css Customizable
Be able to search through severals table in my PostGreSQL DB.
I am currently using Heroku for production.
I want to choose the best one for my needs and that's why I am asking your opinion.
Thanks in advance !
Make sure to separate how you want data displayed (your first two requirements) from how you want it indexed (third) from how you want to deploy.
Let's start backwards. Heroku provides limited support for machine configuration; both options you mention require installation of a service that reads and writes files. Heroku has such an option in two ways: 1) PostgreSQL has a built-in full-text search capability, and 2) Heroku has made Flying Sphinx an option, as well as these other options documented on the Heroku site. The first two options may provide the easiest linkage to your database, but I haven't tried other options, so it's possible they do too. So now you have a search index, deployed.
Real-time "incremental" search is purely a matter of presentation ... and maybe performance. Start typing and you start getting results is nothing more than sending requests via AJAX to the search server, typically after a short delay in typing (maybe 50ms), and handling the display of results. There are a couple of ways to make that simple written up here in this SO answer.
I ended up keeping the PostgreSQL engine for now but used select2 as the jquery for the presentation and was able to get a facebook like search box :
Select2 with Rails and JSON
Thanks for you help !

Proximity searches in Rails

What proximity search options are there for Rails? (Perhaps with pros and cons of each?)
Is a postcode database the way to go?
or using Geocoding with a gem such as Geocoder?
Are there any best practises or gotchas to be aware of?
(Example usage, A Yellow Pages type app where businesses can list, and users can enter their postcode and find businesses that are close to them, or within a radius of specified miles.)
Update: The app is pretty much exactly like the example app above - Businesses can list in the app which is essential a directory (which will have categories for each type of business) and users can go to a category and sort the results by distance (after entering their postcode - so the businesses closest to them, gets shown first). There will be no searching by name or other criteria - it is a simple go to the 'Boxer Dog Breeders' page and sort by distance.
Well the answer depends on what you want to do. If you want simple proximity searches (within a radius and stuff) then the Geocoder gem is more than fine! Now, if you want more advanced search capabilities (polygon, multi-polygon searches etc) I would suggest to go with the PostrgeSQL database and the wonderful PostGIS extension. For use with Rails you should definitely check out the PostGIS adapter for ActiveRecord which comes from the author of a really nice gem called RGeo which uses the superfast libraries GEOS and Proj for the Geospatial calculations.
Otherwise if you find that you need a dedicated search server that has GIS capabilities then you should definitely use ElasticSearch and Ruby has a great gem to aid you with ES called Tire.
Hope I helped!
If you plan to add addational search criteria (eg. name of firm, category) or complex sorting and your DB will grow over 10000 I'm recommend using external search server. For example sphinx search + thinking sphinx.
Here is example of geosearching: http://freelancing-god.github.com/ts/en/geosearching.html
RoR model solutions (like Geocoder) are not very efficient with full text searching.
I don't have experience with Geocoding myself, but Alex Reisner's Geocoder gem looks like the best option, by a mile.
Geocoder is a complete geocoding solution for Ruby. With Rails it adds geocoding (by street or IP address), reverse geocoding (find street address based on given coordinates), and distance queries. It’s as simple as calling geocode on your objects, and then using a scope like Venue.near("Billings, MT").
Checkout the README for a full example on how to use it.

Rails request statistics gem?

I'm looking for a rails plugin to show request statistics (# of sql queries, time, etc) on each request while in development mode. Something like http://getglimpse.com/ would be great. I've seen one or two of these before but for the life of me I can't find them. Any help?
Ideally, it would show in the header or the footer of every page.
I found a few including the one I was thinking about and some others.
This one is amazing so far:
https://github.com/dsboulder/query_reviewer
This is the one I was thinking of:
https://github.com/josevalim/rails-footnotes
This seems to be a similar but better plugin to rails-footnotes:
https://github.com/brynary/rack-bug
May be best to mix and match these, try rack-bug and query_reviewer
A few others are linked from query_reviewer

Smart email reading

I am working on a erp system, being developed using Ruby on Rails. I want to create a sales order by reading the contents of the email. I can recognize by reading the contents if its a sales order or inquiry.
Now a step forward I want to read email and fetch the items in the list. I am planning to take words from the email and search them in the database under items. I can't fix a certain format for the email.
I am going to use following approach.
I'll be using ferret(initially, may switch to sphinx or similar) to search the items in the emails content.
1). Loop through items table and search them for exact phrase match.
Email.find_with_ferret("item+name")
2). Search email for item name split keyword. Email.find_with_ferret("items nice name")
3). Fuzzy search Email.find_with_ferret("items nice name~")
Please help me to improve this.
You're going to need to intercept the emails with rails. Here's a decent article explaining the various approaches to doing this:
http://steve.dynedge.co.uk/2010/09/07/incoming-email-in-rails-3-choosing-the-right-approach/

Resources