How can i search full text with sentence and search any word matched or different configuration
example:
"professor john smith" is searching in model title
it have to display result which matched the "proffessor john smith", "professor john" ", "proffesson smith"
There are lots of fulltext search technologies supports rails. elasticsearch and solar search ar eone of them
Rails cast about integrating solar search is here
There are some technologies compatible with rails. For example sunspot, as #scottxu wrote, or elasticsearch, as #knotito said. Good solution also - sphinx (fast and lite) and thinking_sphinx gem. If you use postgresql as database, and you do not want use external solutions - you can choose pg_search gem, that emplements fulltext search with pg technologies only. I prefer elasticsearch, but it requires JVM, and some people don't like this.
updated:
how to use pg_search:
First, you should add pg_search to gemfile, make bundle install, and add to your model something like:
include PgSearch
pg_search_scope :search_by_title, :against => :title
if you didn't do it before.
After, you can try to test it in rails console:
Professor.search_by_title('professor smith')
For fulltext searches you can use Elasticsearch
To implement that you can follow this railscast
you can use sunspot
description:
Sunspot is a Ruby library for expressive, powerful interaction with the Solr search engine. Sunspot is built on top of the RSolr library, which provides a low-level interface for Solr interaction; Sunspot provides a simple, intuitive, expressive DSL backed by powerful features for indexing objects and searching for them.
Related
I'm new to RoR and jumping into a big RoR project. The project uses a bunch of gems. In fact, the Gemfile.lock file, including dependencies, is 460 lines long. I was told the project went through several different developers, and that there may be a lot of cruft in there.
Is there any way to generate a list of what each gem does? It's not exactly intuitive, especially with names like "capybara" and "cocaine" and "raindrops."
Is there any simple process to determine which gems are required?
You really shouldn't stress too much about what's in the Gemfile.lock at first, just the Gemfile.
To get gem details, I just whipped this little script up to dump summaries of all the gems in your current bundle:
require 'yaml'
gems = `bundle list`
names = gems.scan(/^\s+\*\s+([\w-]+)\s+\(.*\)\s*$/).flatten
names.each do |name|
summary = YAML.parse(`gem spec #{name} summary`).root.value rescue '???'
puts "#{name}: #{summary}"
end
Save it to a file and run it on the command line like so:
ruby whatever-you-saved-it-as.rb
For a project of mine, I got this:
actionmailer: Email composition, delivery, and receiving framework (part of Rails).
actionpack: Web-flow and rendering framework putting the VC in MVC (part of Rails).
actionview: Rendering framework putting the V in MVC (part of Rails).
activemodel: A toolkit for building modeling frameworks (part of Rails).
activerecord: Object-relational mapper framework (part of Rails).
activesupport: A toolkit of support libraries and Ruby core extensions extracted from the Rails framework.
addressable: URI Implementation
annotate: Annotates Rails Models, routes, fixtures, and others based on the database schema.
arel: Arel is a SQL AST manager for Ruby
ast: A library for working with Abstract Syntax Trees.
astrolabe: An object-oriented AST extension for Parser
awesome_print: Pretty print Ruby objects with proper indentation and colors
...
Kinda neat actually.
Assuming that each gem has a meaningful description, you can run something like this from the Rails console:
Gem.loaded_specs.values.map { |g| "#{g.name}: #{g.summary}" }
The dynamic nature of Ruby makes it hard to find unused gems automatically (e.g. through code analysis). However, you can try to remove gems one by one. If your project's test suite passes without a given gem, it is certainly a strong sign that it might be safe to remove it.
how can i integrate Convert_tz of Mysql in thinking sphinx?
i tried to look up for answers but i'am not able to find any.
I'am using ruby - 1.9.3 and rails 3.2 thinking sphinx 2.0.11
eg:
Model.search("", with: {attribute: ">=CONVERT_TZ(#{Time.now}, 'UTC', 'America/New_York')" })
Sphinx has no concept of timezones, and so it doesn't have the CONVERT_TZ function (or anything like it). By default, Sphinx will store times as whatever they're in your database as (very likely UTC), so your best bet is to convert times to the appropriate UTC values when filtering.
And if you want to use greater-than/less-than logic in filters, it needs to be done as a range:
Model.search with: {attribute: Time.zone.now..1.year.from_now}
I have a Ruby on rails 3.2 application. I want to enable text based search on a model that has a lot of data already populated in it. Suppose the name of the model class is Post. I am planning on using elasticsearch since I heard it is one of the best real-time search engines around and I am using tire gem so that my application can interact with elasticsearch.
As I am new to elasticsearch I am having trouble creating indices for the existing data for the model. I am using mongodb as the backend database. Can anyone tell me how to import the indices.
I have already tried
Tire.index "posts" do
import Post.all
end
The error that I got was :
BSON::InvalidObjectId: illegal ObjectId format: Career Guidance
from /Users/anirvan/.rvm/gems/ruby-1.9.3-p125/gems/bson-1.5.1/lib/bson/types/object_id.rb:126:in `from_string'
Can anyone help me out here ?
I use Mysql and this code in bash(from railscasts.com):
rake environment tire:import CLASS=Post FORCE=true
http://www.elasticsearch.org/guide/appendix/clients.html
tire: Ruby API & DSL, with full Rails ActiveModel compatibility and mongoid integration through mebla.
Try it, maybe help you.
Trying to get searching working on Heroku using partial search
The following query generates an SQL error on Heroku, but works correctly in my locally version:
#events.search(params[:search]+":*")
I am using the Heroku shared database service, is this a possible difference in syntax between PostgreSQL versions?
What syntax should I be using to do a partial matching searching against a full-text index in PostgreSQL 8?
Here are the changes in PostgreSQL 9.1.
Perhaps you could try using string interpolation instead of concatenation.
#events.search("#{params[:search]}:*")
I'm not really sure what the kiss emoticon :* adds to texticle's functionality. Maybe I need to learn more SQL.
It turns out that PostgreSQL version 8 does not support partial searches using the :* syntax.
As http://www.postgresql.org/docs/9.0/interactive/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES says, using ":" is for specify prefix matching. E.g. If searching "Australia" with "Aus:" will work but not "ust:*".
So concat OR xxxx LIKE "%yyy%" will works better
You can use the tsearch option with a prefix:
:tsearch => {:prefix => true}
Is there anyway in ruby on rails to make a query using regexp?
I think it might depend on the database. I know in MySQL you can do something like:
Model.find(:conditions => "field REGEXP '.*'")
if you want a true regex, or you can use the LIKE syntax for similar string matching.
While it doesn't have regex, there's also a gem called MetaWhere that provides more advanced finder functionality.