0

I have two users with name 'Alex' and 'Andrei'. When i write query like 'A', I get 0 results. I have to search with the full name and matching capitalization to get a result.

I want for example just query for 'e' end receive 2 records.

    Session s = session.getCurrentSession();

    FullTextSession fullTextSession = Search.getFullTextSession(s);

    QueryBuilder qb = fullTextSession.getSearchFactory()
            .buildQueryBuilder().forEntity(User.class).get();
    org.apache.lucene.search.Query q = qb
            .keyword().onFields("name")
            .matching(query)
            .createQuery();

    org.hibernate.Query hibQuery =
            fullTextSession.createFullTextQuery(q, User.class);

    List<User> results = hibQuery.list();
Andrew Lazarus
  • 18,205
  • 3
  • 35
  • 53
BabyGluk
  • 89
  • 2
  • 12
  • 1
    Analysis sounds like your issue. You should read up on that: https://docs.jboss.org/hibernate/search/3.4/reference/en-US/html_single/#d0e392 . Don't really understand why a query for "e" would find "Alex". Maybe look into ngram analysis, I guess... – femtoRgon Apr 06 '15 at 16:59

2 Answers2

0

You are not showing how you index the first names. This is as well important. For example if you store index them un-analyzed, you need to take indeed capitalization into account. Also as mentioned in the comment, you need to look at the right analyzer. You case would only work if you were to use wildcard queries.

On a tangent, I don't know how close your example is to your actual usecase, but searching for a single character is probably not a typical free-text search use-case.

Community
  • 1
  • 1
Hardy
  • 18,659
  • 3
  • 49
  • 65
0

This particular behavior reminds me one error I got once.

'A' is a stop word (in English language) used by the standard analyzer of Hibernate Search, so you have to precise a custom analyser without this stop word.

These Links could help you

To use a custom analyzer: https://docs.jboss.org/hibernate/search/3.1/reference/en/html/search-mapping.html

To understand what I mean with 'a' like a stop word: Getting error on a specific query

Community
  • 1
  • 1
jpmottin
  • 2,717
  • 28
  • 25