# Wildcard queries on stemmed indexes

**URL:** <https://www.ruby-forum.com/t/wildcard-queries-on-stemmed-indexes/199998>\
**Category:** Ferret\
**Created:** [December 2, 2010, 5:30pm UTC](https://www.ruby-forum.com/t/wildcard-queries-on-stemmed-indexes/199998 "2010-12-02T17:30:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [December 2, 2010, 5:30pm UTC](https://www.ruby-forum.com/t/wildcard-queries-on-stemmed-indexes/199998/1 "2010-12-02T17:30:24Z")

</div>

Hello!

I’m using the German stemming analyzer to index a database using  
acts\_as\_ferret. I have some troube with wildcard queries which I’m  
extensivly using (and needing) for autocompleter fields.

The problem is the following:

In this example, the indexed model contains street names. Some of these  
names are:

- Alte Bürger
- Alter Fährweg
- Am Alten Vorhafen
- …

So lots of names which Street#find\_with\_ferret could match. Let’s try:

# Street.find\_with\_ferret “al\*”

-\> [“Alte Bürger”, “Alter Fährweg”, “Am Alten Vorhafen”, …]

Fine so far. Next:

# Street.find\_with\_ferret “alt\*”

-\> [“Alte Bürger”, “Alter Fährweg”, “Am Alten Vorhafen”, …]

No let’s add another letter:

# Street.find\_with\_ferret “alt\*”

-\> []

Whoops, nothing there. It should match all the same list entries. It  
looks like this happens to all words added to the index using a stemming  
analyzer. Using without wildcards works:

# Street.find\_with\_ferret “alte”

-\> [“Alte Bürger”, “Alter Fährweg”, “Am Alten Vorhafen”, …]

Something similar happens with other search terms:

–\> Database contains “Rasenweg” (“weg” is stripped away by an analyzer  
and also a stopword)

# Street.find\_with\_ferret “rasen\*”

-\> [] # \<-- unexpected

# Street.find\_with\_ferret “rasen”

-\> [“Rasenweg”] # \<-- expected

# Street.find\_with\_ferret “ras\*”

-\> [“Rasenweg”] # \<-- expected

How can I fix this or how is this usually handled? I need to do queries  
like this:

# Street.find\_with\_ferret “(alte~ bü~)||(alte_bü_)”

and it should return “Alte Bürger” in the results. This works when I  
reformulate the query to:

# Street.find\_with\_ferret “alte~||bü~||alte_bü_”

but this delivers way too inaccurate results.
