Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9119029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:17:48+00:00 2026-06-17T05:17:48+00:00

How to configure lucene + hibernate and develop wildcard query which matches some field

  • 0

How to configure lucene + hibernate and develop wildcard query which matches some field by any exact part of that field value? For instance if we have some field “title” indexed and only two entries for it: “My first wildcard query.” and “My second wildcard query.”; then if we query for “irsT WiLdCaRd q” then it has to return only first one. Also it doesn’t has to be case sensitive.

I’ve tried something like this:

    FullTextSession ftSession = org.hibernate.search.Search.getFullTextSession((Session) em.getDelegate());
    QueryContextBuilder qbc = ftSession.getSearchFactory().buildQueryBuilder();
    EntityContext entityContext = qbc.forEntity(Book.class);
    QueryBuilder qb = entityContext.get();
    org.apache.lucene.search.Query q = qb.keyword().wildcard().onField("title")
            .ignoreAnalyzer().matching("*" + QueryParser.escape("irsT WiLdCaRd q").toLowerCase() + "*").createQuery();
    FullTextEntityManager ftEm = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
    final FullTextQuery ftq = ftEm.createFullTextQuery(q, Book.class);
    List list = ftq.getResultList();

and it doesn’t work, because it’s keyword oriented and there’s no analog with wildcard for phrase. Using direct WildcardQuery also doesn’t work(

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:17:49+00:00Added an answer on June 17, 2026 at 5:17 am

    Lucene does not support wildcards in phrase queries. There are strategies on how you represent the data in your index that can allow you to accomplish it.

    You are treating your query as a keyword, it appears. In that case, you should really be treating the field as a keyword when indexing, as well, in which case you would be able to search the whole title as a single term. Phrases and keywords with spaces are very different things to Lucene, and you can’t use them interchangeably.

    The better solution, though, may be to rely on scoring to provide the best match on a set of term queries. If you just use a standard analyzer to reduce the query you indicated to a set of three terms: *irsT WiLdCaRd and q*, while both of the terms you indicated would be found, the one you want would be returned first, with a significantly higher score. You could hone the acceptable found documents somewhat, searching with required terms, like: +title:*irsT +title:WiLdCaRd +title:q*. That would eliminate any matches that do not contain all three terms, though the order of them or presence of other terms wouldn’t prevent matching.

    Also, another note: queries like *irst are not allowed unless you set it to enable leading wildcards. This is generally discouraged if you can avoid it. Searching with leading wildcards can be expected to be very slow, unless you’ve optimized your index for them (See SOLR’s ReversedWildcardFilterFactory, for instance).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to configure MySQL so that it has some kind of execution
I am trying to configure my xmonad.hs so that when I start my session
I am trying to configure the CLIENTS table on my database such that if
Is it possible to configure Apache Tomcat to simulate network latency that a client
Is it possible to configure nginx to query a service (not DNS) to determine
I've written a QueryParser that is looks a little like Lucene's QueryParser . I've
My database has three columns, which I configured lucene to index. However, I can
I am trying to configure the hibernate.cfg.xml file to use memcache. I see the
I'm having an issue with Lucene's Term [Boosting][1] query syntax, specifically in Ruby on
Is it possible to configure ACS so that, if it receives an input claim

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.