Need your thoughts on a plugin I'm working on.

1 view
Skip to first unread message

Erol Fornoles

unread,
Oct 5, 2009, 10:34:20 AM10/5/09
to Philippine Ruby Users Group (PRUG/PhRUG)
Hi everyone!

I'm working on a plugin which allows you to do tagging and querying of
similar sounding names or words on ActiveRecord models. The plugin is
using double metaphone to produce the phonetic tags, and - as is with
almost all RoR apps - is db-agnostic, or atleast it's meant to be db-
agnostic.

The plugin is available at http://github.com/Erol/has_similar.

I'd appreciate your thoughts and/or objective criticisms. Thanks!

katz

unread,
Oct 7, 2009, 1:25:18 AM10/7/09
to ruby...@googlegroups.com
If this will work with searchlogic or thinking sphinx for instance then it's very a good idea.
Although it will not return the exact results. You can indicate some results as a suggestion. Pretty much like google when you search "Queenland"
It will return  "
Did you mean: Queensland "

I have no luck testing with script/console even with english gem installed by the way so I couldn't test your extension to ActiveRecord.

Pretty cool stuff. Looking forward to developments of this plugin Erol. Great work...




Erol Fornoles

unread,
Oct 7, 2009, 3:47:37 AM10/7/09
to Philippine Ruby Users Group (PRUG/PhRUG)
On Oct 7, 1:25 pm, katz <bridgeuto...@gmail.com> wrote:
> If this will work with searchlogic or thinking sphinx for instance then
> it's very a good idea.
> Although it will not return the exact results. You can indicate some
> results as a suggestion. Pretty much like google when you search "Queenland"
> It will return  "Did you mean: */Queensland/*
> <http://www.google.com.ph/search?hl=en&ei=WiXMSrTvKIOOswP4kJCdAQ&sa=X&...>
> "
>
> I have no luck testing with script/console even with english gem
> installed by the way so I couldn't test your extension to ActiveRecord.
>
> Pretty cool stuff. Looking forward to developments of this plugin Erol.
> Great work...

Sorry about that. Sloppy field naming resulted in a conflict with AR.
Should be fixed now; you'll have to delete and regenerate the
phonetic_tag_migration though.

It should work along with Sphinx, although the plugin maintains
separate indexes (or tags) besides the ones the Sphinx daemon uses.
I've seen discussions on how to implement phonetic matching via
metaphone or double metaphone to Sphinx installations, but really
never got to try those myself.

The plugin is different to Sphinx in that it maintains indexes in real-
time (or at least that's the goal); indexes or tags for a record are
immediately built or rebuilt once it is created or updated, unlike in
Sphinx where you have to wait for, let's say, a cron-job to run.

Will be thinking how to approach the "suggestions" idea. I appreciate
it the input very much.

katz

unread,
Oct 7, 2009, 4:21:15 AM10/7/09
to ruby...@googlegroups.com
Yeah it's working now..
>> Place.find_all_by_similar_name "Manilla"
=> [#<Place id: 2, name: "Manila", created_at: "2009-10-07 08:08:20", updated_at: "2009-10-07 08:08:20">]
>> Place.create! :name=>"Queensland"
=> #<Place id: 3, name: "Queensland", created_at: "2009-10-07 08:09:36", updated_at: "2009-10-07 08:09:36">
>> Place.find_all_by_similar_name "Queenland"
=> []
>> Place.find_all_by_similar_name "Queenslans"
=> [#<Place id: 3, name: "Queensland", created_at: "2009-10-07 08:09:36", updated_at: "2009-10-07 08:09:36">]
>>

Thanks for the info on Sphinx.
The plugin itself works and having that finder method is pretty useful. You need not really implement my suggestion. I was just looking for options on how to have that feature similar to what I've described.

Erol Fornoles

unread,
Oct 11, 2009, 2:24:02 PM10/11/09
to Philippine Ruby Users Group (PRUG/PhRUG)
Thanks for the feedback Katz!

I have a new problem though. Does anyone have an idea on how the below
SQL could be optimized?

SELECT people.* FROM people WHERE EXISTS (SELECT t1.id FROM tags t1
WHERE t1.person_id = people.id AND t1.word = "tag1") AND EXISTS
(SELECT t2.id FROM tags t2 WHERE t2.person_id = people.id AND t2.word
= "tag2")

Aries Andrada

unread,
Oct 11, 2009, 4:07:52 PM10/11/09
to ruby...@googlegroups.com
Hi Erol,

Try joining the tables instead...

select people.*
from people
join tags t1 on t1.person_id = people.id and t1.word = 'tag1'
join tags t2 on t2.person_id = people.id and t2.word = 'tag2'

Regards,

Aries

Erol Fornoles

unread,
Oct 11, 2009, 5:03:01 PM10/11/09
to Philippine Ruby Users Group (PRUG/PhRUG)
On Oct 12, 4:07 am, Aries Andrada <aries.andr...@gmail.com> wrote:
> Hi Erol,
>
> Try joining the tables instead...
>
> select people.*
> from people
> join tags t1 on t1.person_id = people.id and t1.word = 'tag1'
> join tags t2 on t2.person_id = people.id and t2.word = 'tag2'
>
> Regards,
>
> Aries

Yep, this ought to work. Thanks!
Reply all
Reply to author
Forward
0 new messages