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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:51:23+00:00 2026-05-20T07:51:23+00:00

In an attempt to get some more contextually relevant search results I’ve decided to

  • 0

In an attempt to get some more contextually relevant search results I’ve decided to have a play with lucene.net although I’m very new to it and I’ve found it not to be the most intuitive library I’ve come across. This isn’t helped by the lack of relevant examples out there to help me figure it out.

I’m using simple lucene to build my index and that seems to be working perfectly:

Field f = null;
Document document = new Document();

document.Add(new Field("id", dl.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));

f = new Field("category", dl.CategoryName.ToLowerInvariant(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
f.SetBoost(5);
document.Add(f);

f = new Field("company_name", dl.CompanyName.ToLowerInvariant(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
f.SetBoost(2);
document.Add(f);

document.Add(new Field("description", dl.Description.ToLowerInvariant(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
document.Add(new Field("meta_keywords", dl.Meta_Keywords.ToLowerInvariant(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
document.Add(new Field("meta_description", dl.Meta_Description.ToLowerInvariant(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));

//And a few more fields

Based on this index I first tried a query along these lines:

var whatParser = new MultiFieldQueryParser(
    global::Lucene.Net.Util.Version.LUCENE_29,
    new string[] { "company_name", "description", "meta_keywords", "meta_description", "category" },
    analyzer);

whatQuery = whatParser.Parse("search".ToLowerInvariant());

This worked great up until the search term became more than 1 word. Next up was a phrase query.

whatQuery = new PhraseQuery();
whatQuery.Add(new Term("company_name", what));
whatQuery.Add(new Term("description", what));
whatQuery.Add(new Term("meta_keywords", what));
whatQuery.Add(new Term("meta_description", what));
whatQuery.Add(new Term("category", what));

Which i then found threw the error: All phrase terms must be in the same field

So, where am I going wrong? Do you have any suggestions on how to fix it? I’m open to changing the search technology entirely if there are better suggestions out there.

Some additional information which may be useful

  • All results are sorted in the end via new Sort(new SortField[] {new SortField("is_featured", SortField.STRING, true),SortField.FIELD_SCORE})
  • There are some additional search criteria so each query is added to a Boolean query with occur set to SHOULD

Thanks for your help.

  • 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-20T07:51:24+00:00Added an answer on May 20, 2026 at 7:51 am

    I think the BooleanClause.Occur.SHOULD is the issue. We use it like this:

    string[] fieldList = { "field1", "field2", "field3"; 
    
    //for us the field list varies .. there are other ways to create this array of course
    List<BooleanClause.Occur> occurs = new List<BooleanClause.Occur>();
    foreach (string field in fieldList)
        occurs.Add(BooleanClause.Occur.SHOULD);
    
    if(!string.IsNullOrEmpty(multiWordPhrase))
    {
        Query q = MultiFieldQueryParser.Parse(multiWordPhrase, fieldList, occurs.ToArray(), new StandardAnalyzer());
        return q;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an image that I get and attempt to load into a graphics
In a attempt to put some more oop in a program i am looking
When I attempt to run the following test in IntelliJ IDEA I get the
When I attempt to instantiate my instance of the base class I get the
When I attempt to connect to SQL server using enterprise manager I get the
When I attempt to debug a simple program with gdb on cygwin I get
When I attempt to open a file to write, I get an error: Ada.IO_Exceptions.Name_Error
In an attempt to develop a hard disk analytic tool, I'm trying to get
In Java, is it possible to attempt a cast and get back null if
To practise some more bits of python I've been having a go at the

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.