1

i've implemented the hibernate search orm (LATEST lucene_version) that search words contains a entry query :

    FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
    QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory()
            .buildQueryBuilder()
            .forEntity(Application.class)
            .get();

    Query queryName = queryBuilder
            .keyword().fuzzy().withEditDistanceUpTo(2).withPrefixLength(2)
            .onField("name")
            .matching("*" + q + "*")
            .createQuery();

this queryName cannot find words like 'Wikicrédit' or 'Wikipro' or 'WikiCash' if my query is 'q=Wiki'

How can i enhance those instructions to get words that start with 'Wiki%' independently of edit distance !

Mirlo
  • 625
  • 9
  • 26

1 Answers1

1

Either:

  1. Use the simpleQueryString query and type your query as Wiki*.
  2. Declare a separate name-edgengram field with an edge-ngram analyzer that will index Wikicrédit as [W, Wi, Wik, Wiki, Wikic, Wikicr, ...] and then query that field, as desribed in this answer.
yrodiere
  • 9,280
  • 1
  • 13
  • 35
  • how can i return exactly "Wikipro" if my query is "Wikipro" ? – Mirlo Jul 15 '21 at 11:58
  • @Mirlo Not sure what your problem is, but if you used the edge-ngram analyzer and searching for `Wikipro` returns documents containing `Wikicrédit`, then you probably forgot to override the analyzer at query time. See the second part of [the answer I mentioned](https://stackoverflow.com/a/46904863/6692043) where I tell you to use `overridesForField`. – yrodiere Jul 16 '21 at 12:52