On Jul 1, 2012, at 9:04 AM, sehrguey o. wrote:
> dear each, and all and others,
>
> being a completeest newbie to RoR and having got dumb by a month or so
> of googling how to add search faculty to a web app, I ask you for
> help.
>
> All I got is a database of 200 records so there is no need for sphinxes,
> sunspots, elasticsearches, searchlogics, ferrets and other highly
> esteemed and advanced engines and plugins. Thank you, sir. No.
>
> I humbly ask for a list of files (and their contents) to be added to a
> new app for user to get/see table of rows after s/he fills
> text_tag_field and clicks submit button.
I built something like this as my first paying Rails job, a couple summers ago. I used Paperclip to store the external files in my mode, so to get the content of the text files (in my case, they were PDFs), I used a custom Paperclip processor (based on the Thumbnail processor that comes with Paperclip) to pipe the content of each uploaded file through the venerable pdftotext Unix command. https://gist.github.com/3028403
The results were not good enough to show the world (layout was destroyed) but the text content was extracted into a plain_text attribute on my model, and that's what I searched within.
The very simplest search technique of all is the substring match. This ignores dozens of years of search technology to simply answer the question "is this string present anywhere within that string?" In SQL, it looks like this: "SELECT * FROM `foos` WHERE `bar` LIKE '%baz%'. In Rails 3+, you would write this in your controller like this:
@foos = Foo.where(["bar LIKE '%?%'",params[:q]])
Hope that's enough to get you started. There's also a number of Railscast episodes about this, starting with this humble substring match, and enumerating some simple Gems that can remove the grunt-work for you, like MetaSearch.
Walter
>
> Don't send me to RailsEpisodes, please, I've sifted them with tons of
> other crap.
>
> yours,
> sehrguey
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.
>
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.
No comments:
Post a Comment