On 16.06.2008, at 13:08, Max Williams wrote:
Gaudi Mi wrote:
I've got Ferret up and running for a Rails application and I'd like
to
be able to use autocomplete in my text search field so that as the
user
is typing each character of the search term, the index is queried for
matching terms starting with those characters, and they are
displayed in
a list under the search box, like Google Suggest.
I have searched the Ferret API but I can't find a way to do for
example:
Show all words in index that start with 's', then 'sp', then 'spa',
etc.
This might be accomplished by using a TermEnum (http://ferret.davebalmain.com/api/classes/Ferret/Index/TermEnum.html
) which basically is a list of all terms present in the index in a
given field. Using term_enum.skip_to('s') should bring back the first
term starting with letter 's', then get all other terms with s by
calling term_enum.next as often as necessary.
Never tried this, but it should work.
However the 'common' way for autocomplete is indeed to base the
completion on past searches, i.e. index user's successful queries and
suggest matching past queries while the user is typing.
If that's really not what you want, you could also build up a second
index containing all the terms that occur in your data, each as a
document on its own (like your own dictionary), and get suggestions
from there, with fuzzy queries if you like. This can also be used for
'did you mean' stuff in case the user has a typo in his query and got
no results because of that.
Cheers,
Jens
--
Jens Krämer
Finkenlust 14, 06449 Aschersleben, Germany
VAT Id DE251962952
http://www.jkraemer.net/ - Blog
http://www.omdb.org/ - The new free film database
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk