Implement fuzzy search functionality

Bug #669828 reported by Morten Haraldsen on 2010-11-02
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Querydsl
Fix Released
Medium
Timo Westkämper

Bug Description

It is currently not possible to issue Lucene FuzzyQuery searches. I found a reference to a test-case for it but the functionality is not implemented yet. I like the syntax as found in the SimpleTest.java test in /tags/QUERYDSL_1_3_16/
<code>
// Fuzzy
// roam~ or roam~0.8
// c.ContactName.Like("roam") or c.ContactName.Like("roam", 0.8)
        // TODO
</code>

If anyone can tell me where to start I will be happy to implement it myself and provide a patch.

Thanks for your bug report. You can wrap arbitrary Lucene Query instances as com.mysema.query.lucene.QueryElement instances.

I just commited the following utility class with supports the creation of fuzzy queries as Querydsl filters :

public final class LuceneUtils {

    public static BooleanExpression fuzzyLike(Path<String> path, String value){
        Term term = new Term(path.getMetadata().getExpression().toString(), value);
        return new QueryElement(new FuzzyQuery(term));
    }

    public static BooleanExpression fuzzyLike(Path<String> path, String value, float minimumSimilarity){
        Term term = new Term(path.getMetadata().getExpression().toString(), value);
        return new QueryElement(new FuzzyQuery(term, minimumSimilarity));
    }

    public static BooleanExpression fuzzyLike(Path<String> path, String value, float minimumSimilarity, int prefixLength){
        Term term = new Term(path.getMetadata().getExpression().toString(), value);
        return new QueryElement(new FuzzyQuery(term, minimumSimilarity, prefixLength));
    }

    private LuceneUtils(){}

}

Feel free to suggest other additions.

Changed in querydsl:
status: New → Fix Committed
assignee: nobody → Timo Westkämper (timo-westkamper)
importance: Undecided → Medium
Morten Haraldsen (m-haraldsen) wrote :

Wow! I just have to say that this teams response time is nothing short of incredible! Thank you!

You're welcome and thanks for your kind words.

Released in 2.0.4

Changed in querydsl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers