# Searching for terms in free-form text

**URL:** <https://www.ruby-forum.com/t/searching-for-terms-in-free-form-text/86092>\
**Category:** Ferret\
**Created:** [February 19, 2007, 8:15pm UTC](https://www.ruby-forum.com/t/searching-for-terms-in-free-form-text/86092 "2007-02-19T20:15:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sonia\_Lyris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@Sonia\_Lyris](https://www.ruby-forum.com/u/Sonia_Lyris)\
**Post date:** [February 19, 2007, 8:15pm UTC](https://www.ruby-forum.com/t/searching-for-terms-in-free-form-text/86092/1 "2007-02-19T20:15:39Z")

</div>

What is the best way to search a (possibly long) string of free-form  
text (like, say, an email) for occurrances of some set of key phrases  
of interest? Fuzzy or not; I’ll take what I can get.

Thanks in advance!

–  
Sonia Lyris | removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Sonia\_Lyris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@Sonia\_Lyris](https://www.ruby-forum.com/u/Sonia_Lyris)\
**Post date:** [February 20, 2007, 2:16pm UTC](https://www.ruby-forum.com/t/searching-for-terms-in-free-form-text/86092/2 "2007-02-20T14:16:32Z")

</div>

Hi!

On Mon, Feb 19, 2007 at 10:44:07AM -0800, Sonia Lyris wrote:

> What is the best way to search a (possibly long) string of free-form  
> text (like, say, an email) for occurrances of some set of key phrases  
> of interest? Fuzzy or not; I’ll take what I can get.

could you be a little bit more specific in what you want to do? For  
finding out if a phrase occurs in a single piece of text a regex  
could be sufficient, but I doubt that’s what you’re asking for 🙂

of course you can do this with ferret, too:

require ‘rubygems’  
require ‘ferret’  
index = Ferret::I.new  
index \<\< ‘your text here’  
top\_docs = index.search ‘text’  
puts ‘found text’ if top\_docs.total\_hits \> 0

Jens

–  
Jens Krämer  
webit! Gesellschaft für neue Medien mbH  
Schnorrstraße 76 | 01069 Dresden  
Telefon +49 351 46766-0 | Telefax +49 351 46766-66  
removed\_email\_address@domain.invalid | [www.webit.de](http://www.webit.de)

Amtsgericht Dresden | HRB 15422  
GF Sven Haubold, Hagen Malessa
