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 9015729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:49:25+00:00 2026-06-16T03:49:25+00:00

To allow users to search across multiple fields with Lucene 3.5 I currently create

  • 0

To allow users to search across multiple fields with Lucene 3.5 I currently create and add a QueryParser for each field to be searched to a DisjunctionMaxQuery. This works great when using OR as the default operator but I now want to change the default operator to AND to get more accurate (and fewer) results.

Problem is, queryParser.setDefaultOperator(QueryParser.AND_OPERATOR) misses many documents since all terms must be in atleast 1 field.

For example, consider the following data for a document: title field = “Programming Languages”, body field = “Java, C++, PHP”. If a user were to search for Java Programming this particular document would not be included in the results since the title nor the body field contains all terms in the query although combined they do. I would want this document returned for the above query but not for the query HTML Programming.

I’ve considered a catchall field but I have a few problems with it. First, users frequently include per field terms in their queries (author:bill) which is not possible with a catchall field. Also, I highlight certain fields with FastVectorHighlighter which requires them to be indexed and stored. So by adding a catchall field I would have to index most of the same data twice which is time and space consuming.

Any ideas?

  • 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-16T03:49:26+00:00Added an answer on June 16, 2026 at 3:49 am

    Guess I should have done a little more research. Turns out MultiFieldQueryParser provides the exact functionality I was looking for. For whatever reason I was creating a QueryParser for each field I wanted to search like this:

    String[] fields = {"title", "body", "subject", "author"};
    QueryParser[] parsers = new QueryParser[fields.length];      
    for(int i = 0; i < parsers.length; i++)
    {
       parsers[i] = new QueryParser(Version.LUCENE_35, fields[i], analyzer);
       parsers[i].setDefaultOperator(QueryParser.AND_OPERATOR);
    }
    

    This would result in a query like this:

    (+title:java +title:programming) | (+body:java +body:programming)
    

    …which is not what I was looking. Now I create a single MultiFieldQueryParser like this:

    MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_35, new String[]{"title", "body", "subject"}, analyzer);
    parser.setDefaultOperator(QueryParser.AND_OPERATOR);
    

    This gives me the query I was looking for:

    +(title:java body:java) +(title:programming body:programming)
    

    Thanks to @seeta and @femtoRgon for the help!

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

Sidebar

Related Questions

I have an application that allow users to search on multiple columns (prod_name,prod_desc) So
I am currently developing a an application to allow users to search through a
I am writing something that will allow users to search through a log of
I am wanting to allow users to tag items so that they can search
I've created a search with a couple of comboboxes that allow users to filter
I'm creating a set of search panes that allow users to tweak their results
I'm creating eBay style search panes that allow users to narrow their results set
(Using MySQL and PHP) I have a search form that will allow my users
I have implemented a UISearchDisplayController that allows users to search a table. Currently the
I am using this page to allow users to search for Points Of Interest

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.