# How to implement full-text search with OR just like google?

**URL:** <https://www.ruby-forum.com/t/how-to-implement-full-text-search-with-or-just-like-google/60770>\
**Category:** Rails\
**Created:** [May 17, 2006, 10:25am UTC](https://www.ruby-forum.com/t/how-to-implement-full-text-search-with-or-just-like-google/60770 "2006-05-17T10:25:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geogeway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d2c977/32.png) [@Geogeway](https://www.ruby-forum.com/u/Geogeway)\
**Post date:** [May 17, 2006, 10:25am UTC](https://www.ruby-forum.com/t/how-to-implement-full-text-search-with-or-just-like-google/60770/1 "2006-05-17T10:25:14Z")

</div>

The current full-text search will return the AND collection results,for  
example,if we use Article.search(“aa bb”),then the articles that include  
“aa” and “bb” in the fields will be returned,how to return the articles  
that include “aa” OR “bb” effectly? A stumb method is to setup two  
queries respectly and collect them together with remove the repeated  
items,how ever paginator will be very difficult to use because it is  
hard to locate the offset when processing the next page.

How google do that?  
if we input aa bb in the search box,the results has the relation of OR  
but not AND,with paginator followed.

Can anybody help me with that?

Thanks a lot

---

<div class="post-metadata">

**Author:** ![Geogeway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d2c977/32.png) [@Geogeway](https://www.ruby-forum.com/u/Geogeway)\
**Post date:** [May 17, 2006, 10:42am UTC](https://www.ruby-forum.com/t/how-to-implement-full-text-search-with-or-just-like-google/60770/2 "2006-05-17T10:42:29Z")

</div>

Hey George,

a little mor information please… What are you using to provide your  
fulltext-feature:  
[http://poocs.net/articles/2006/04/06/introducing-acts\_as\_searchable](http://poocs.net/articles/2006/04/06/introducing-acts_as_searchable) or  
[http://projects.jkraemer.net/acts\_as\_ferret/wiki](http://projects.jkraemer.net/acts_as_ferret/wiki) or something completely  
different.

By the way: Google returns “AND” results at least for the highest ranked  
results as well. This is what the user is expecting when he is typing in  
more than one word. IMHO it would be most user friendly to return “AND”  
results if there are some, “OR” if not (and show the user that there are  
no  
results for his “AND” query). Maybe you might give the user the  
opportunity  
to search more vague (by “OR”) if there were already “AND”-results  
returned…

Regards  
Jan

---

<div class="post-metadata">

**Author:** ![Geogeway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d2c977/32.png) [@Geogeway](https://www.ruby-forum.com/u/Geogeway)\
**Post date:** [May 17, 2006, 11:01am UTC](https://www.ruby-forum.com/t/how-to-implement-full-text-search-with-or-just-like-google/60770/3 "2006-05-17T11:01:05Z")

</div>

Thanks,i will try acts\_as\_ferret

But I can not start the demo app:  
F:\Download\acts\_as\_ferret\_trunk\demo\>ruby script/server  
=\> Booting WEBrick…  
F:\Download\acts\_as\_ferret\_trunk\demo\>

The webrick aborted unnormally,if i install the plugin to my own  
app,same abort happens,can u tell me the reason?

Jan P. wrote:

> Hey George,
> 
> a little mor information please… What are you using to provide your  
> fulltext-feature:  
> [http://poocs.net/articles/2006/04/06/introducing-acts\_as\_searchable](http://poocs.net/articles/2006/04/06/introducing-acts_as_searchable) or  
> [http://projects.jkraemer.net/acts\_as\_ferret/wiki](http://projects.jkraemer.net/acts_as_ferret/wiki) or something completely  
> different.
> 
> By the way: Google returns “AND” results at least for the highest ranked  
> results as well. This is what the user is expecting when he is typing in  
> more than one word. IMHO it would be most user friendly to return “AND”  
> results if there are some, “OR” if not (and show the user that there are  
> no  
> results for his “AND” query). Maybe you might give the user the  
> opportunity  
> to search more vague (by “OR”) if there were already “AND”-results  
> returned…
> 
> Regards  
> Jan

---

<div class="post-metadata">

**Author:** ![Geogeway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d2c977/32.png) [@Geogeway](https://www.ruby-forum.com/u/Geogeway)\
**Post date:** [May 17, 2006, 11:10am UTC](https://www.ruby-forum.com/t/how-to-implement-full-text-search-with-or-just-like-google/60770/4 "2006-05-17T11:10:10Z")

</div>

have you installed ferret beforehand?

> gem install ferret

Regards  
Jan

---

<div class="post-metadata">

**Author:** ![Geogeway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d2c977/32.png) [@Geogeway](https://www.ruby-forum.com/u/Geogeway)\
**Post date:** [May 17, 2006, 11:34am UTC](https://www.ruby-forum.com/t/how-to-implement-full-text-search-with-or-just-like-google/60770/5 "2006-05-17T11:34:35Z")

</div>

has got to be create database ferret\_demo; create database ferret\_test;  
of  
course…

Jan

---

<div class="post-metadata">

**Author:** ![Geogeway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d2c977/32.png) [@Geogeway](https://www.ruby-forum.com/u/Geogeway)\
**Post date:** [May 17, 2006, 5:34pm UTC](https://www.ruby-forum.com/t/how-to-implement-full-text-search-with-or-just-like-google/60770/6 "2006-05-17T17:34:55Z")

</div>

Hi,Jan  
I have tested acts\_as\_ferret,and it perform well.However,there are two  
difficults that prevent me from using:

1. It does not support utf8’s searching,if i search other unicode  
language,it always returns nothing
2. It is difficult to combine the paginator,how to get sum of the  
resultsets that the paginator uses?  
@results =  
Tutorial.find\_by\_contents(@query,:first\_doc=\>10,:num\_docs=\>10)  
can be used to search with the offset and limit,but the sum is hard to  
get.

Can you help with that? very thanks!

George

Jan P. wrote:

> has got to be create database ferret\_demo; create database ferret\_test;  
> of  
> course…
> 
> Jan

---

<div class="post-metadata">

**Author:** ![Geogeway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d2c977/32.png) [@Geogeway](https://www.ruby-forum.com/u/Geogeway)\
**Post date:** [May 17, 2006, 11:28am UTC](https://www.ruby-forum.com/t/how-to-implement-full-text-search-with-or-just-like-google/60770/7 "2006-05-17T11:28:19Z")

</div>

The README of the demo isn’t exactly detailed, I’ve tried it myself on  
windows since your path indicates that your on a windows box. The steps:

1. gem install ferret
2. cd to the demo\db directory
3. mysql -uroot -p
4. create ferret\_demo; create ferret\_test;
5. use ferret\_demo; source schema.sql; - do the same for ferret\_test
6. cd to demo\config and put in values that satisfy your environment
7. cd to demo root
8. rake \>\> are there any failures? rule them out…
9. ruby script/server
10. [http://localhost:3000/content](http://localhost:3000/content) - put in some of it
11. [http://localhost:3000/search](http://localhost:3000/search) - enjoy ferret fulltext search and  
learn  
about it’s query language on [http://ferret.davebalmain.com](http://ferret.davebalmain.com) it should  
satisfy  
your needs
12. maybe / hopefully: post a patch for a better demo readme to  
acts\_as\_ferret trac and participate…

Regards  
Jan

---

<div class="post-metadata">

**Author:** ![Geogeway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d2c977/32.png) [@Geogeway](https://www.ruby-forum.com/u/Geogeway)\
**Post date:** [May 17, 2006, 6:19pm UTC](https://www.ruby-forum.com/t/how-to-implement-full-text-search-with-or-just-like-google/60770/8 "2006-05-17T18:19:11Z")

</div>

Hi, George,

may I at first ask which languages you want to index?

I think you are on windows, is this right? IMHO there is still a problem  
with the native extension (cFerret, the superfast c library of ferret)  
to be  
build on windows. I think because of this the stemming files like  
\*stem\_UTF\_8\_portuguese.h  
stem\_ISO\_8859\_1\_italian.h \*won’t be build on your system. As I’ve  
understood  
cFerret solved many - if not all - UTF-8 problems, but as I’ve said you  
might be bound to the pure ruby version on windows until the problems of  
building cFerret on windows are ruled out.

Have you got a linux box available? If you’ve got some time (but don’t  
hold  
your breath 😉 you might wait for the problems of ferret on windows  
being  
solved, or provide patches yourself: [http://ferret.davebalmain.com](http://ferret.davebalmain.com) .  
Have  
you had a look at acts\_as\_searchable and hyperestraier if this does what  
you  
need? Personally I’m preferring ferret and acts\_as\_ferret because of  
it’s  
lucene roots and a great community but hyperestraier is a superb library  
too  
and acts\_as\_searchable (which is based on hyperestraier) might be the  
right  
tool for your job…

Regards  
Jan P.

---

<div class="post-metadata">

**Author:** ![Geogeway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d2c977/32.png) [@Geogeway](https://www.ruby-forum.com/u/Geogeway)\
**Post date:** [May 18, 2006, 3:03am UTC](https://www.ruby-forum.com/t/how-to-implement-full-text-search-with-or-just-like-google/60770/9 "2006-05-18T03:03:18Z")

</div>

Hi,Jan  
I am developing the web app under windows and plan to deploy the app on  
linux,therefore at first all the tasks have to be done in win32.  
I plan to search multi language which the most important two is English  
and chinese,i get nothing if the input text is Chinese.I will try both  
ferret and acts\_as\_searchable and have a comparison…

Jan P. wrote:

> Hi, George,
> 
> may I at first ask which languages you want to index?
> 
> I think you are on windows, is this right? IMHO there is still a problem  
> with the native extension (cFerret, the superfast c library of ferret)  
> to be  
> build on windows. I think because of this the stemming files like  
> \*stem\_UTF\_8\_portuguese.h  
> stem\_ISO\_8859\_1\_italian.h \*won’t be build on your system. As I’ve  
> understood  
> cFerret solved many - if not all - UTF-8 problems, but as I’ve said you  
> might be bound to the pure ruby version on windows until the problems of  
> building cFerret on windows are ruled out.
> 
> Have you got a linux box available? If you’ve got some time (but don’t  
> hold  
> your breath 😉 you might wait for the problems of ferret on windows  
> being  
> solved, or provide patches yourself: [http://ferret.davebalmain.com](http://ferret.davebalmain.com) .  
> Have  
> you had a look at acts\_as\_searchable and hyperestraier if this does what  
> you  
> need? Personally I’m preferring ferret and acts\_as\_ferret because of  
> it’s  
> lucene roots and a great community but hyperestraier is a superb library  
> too  
> and acts\_as\_searchable (which is based on hyperestraier) might be the  
> right  
> tool for your job…
> 
> Regards  
> Jan P.
