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

  • Home
  • SEARCH
  • 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 6342769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:18:22+00:00 2026-05-24T20:18:22+00:00

I am using Lucene to index my database and then perform a phrase search

  • 0

I am using Lucene to index my database and then perform a phrase search on a specific field(field name: keyword).
I am using following code currently:

        String userQuery = request.getParameter("query");
        //create standard analyzer object
        analyzer = new StandardAnalyzer(Version.LUCENE_30);
                    Analyzer analyze=AnalyzerUtil.getPorterStemmerAnalyzer(analyzer);
        //create File object of our index directory
        File file = new File(LUCENE_INDEX_DIRECTORY);
        //create index reader object
        reader = IndexReader.open(FSDirectory.open(file),true);
        //create index searcher object
        searcher = new IndexSearcher(reader);
        //create topscore document collector
        collector = TopScoreDocCollector.create(1000, false);
        //create query parser object
        parser = new QueryParser(Version.LUCENE_30,"keyword", analyze);
                    parser.setAllowLeadingWildcard(true);
        //parse the query and get reference to Query object
        query = parser.parse(userQuery);
        //********Line 1***********************
                    //search the query
        searcher.search(query, collector);
        hits = collector.topDocs().scoreDocs;
        //check whether the search returns any result
        if(hits.length>0){//Code to retrieve hits}

This code works fine for stemming, but now I want to also expand my query to do synonym search like if I enter “Man” and my lucene index has a entry “male”, it would still be able to give me that as a hit.
I tried to add this at Line 1 in the above code query=SynExpand.expand(userQuery,
searcher, analyze,"keyword",serialVersionUID);

But it doesn’t give me any result.
I also want to introduce spell check, where in if I enter “ubelievable” instead of “unbelievable” it would still give me a result.

I have no idea why synonym expansion isn’t working for me and how to do spelling check.Please if someone could guide me I will be really grateful.

Thanks!

  • 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-05-24T20:18:23+00:00Added an answer on May 24, 2026 at 8:18 pm

    Fuzzy search may be done by query keyword modifier, namely by adding tilde:

    keyword:ubelievable~
    

    See Lucene Parser Syntax for more details and other types of queries that may be interesting to you.

    There are 2 ways of dealing with synonyms. Query expansion you are trying to use relies on WordNet. As SynExpand‘s documentation says, you should first invoke Syns2Index to use expansion. This is easy way, but it works only with English words.

    If you need to add support for multiple languages or add your own synonyms, you can use synonym injection during indexing. The idea is to write your own analyzer that will inject synonyms from your own dictionary into indexed documents. This may sound hard to implement, but fortunately there’s excellent example in Lucene in Action book (source code is available for free, see lia.analysis.synonym package. Though, I highly recommend to get your copy of this nice book).

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

Sidebar

Related Questions

Am building a Book search API using Lucene. I need to index Book Name,Author,
I've built a search index using the PHP Zend Framework Search (based on Lucene).
I'm using Lucene.Net to implement a search website (to search PDFs). Once the keyword
I am trying to index a table in a database using Lucene. I use
I am using Lucene to search a contacts database. By contacts I mean a
I'm constructing a simple search form for our support ticket database using Lucene.Net, and
We are using Hibernate search to search the lucene index annoted in my entity.
I'm trying to start using lucene. The code, I'm using to index documents is:
I'm using Lucene to search through an index of XML documents. I'm supposed to
I am using Zend Search Lucene to index a number of DOCX files. $index

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.