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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:36:00+00:00 2026-05-13T01:36:00+00:00

I’m very new to lucene.net. I wrote this simple console app in C# which

  • 0

I’m very new to lucene.net. I wrote this simple console app in C# which indexes some fake data. I then wanted to be able to search the index for various terms using a booleanquery.

I never get any results back. Here is the code. Any help would be greatly appreciated. Thanks.

    static void Main(string[] args)
    {
        StandardAnalyzer analyzer = new StandardAnalyzer();
        IndexWriter writer = new IndexWriter("Test", analyzer, true);
        Console.WriteLine("Creating index");
        for (int i = 0; i < 1500; i++)
        {
            Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
            doc.Add(new Lucene.Net.Documents.Field("A", i.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
            doc.Add(new Lucene.Net.Documents.Field("B", "LALA" + i.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
            doc.Add(new Lucene.Net.Documents.Field("C", "DODO" + i.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
            doc.Add(new Lucene.Net.Documents.Field("D", i.ToString() + " MMMMM", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
            writer.AddDocument(doc);
        }            
        writer.Optimize();
        writer.Close();

        BooleanQuery query = new BooleanQuery();
        query.Add(new WildcardQuery(new Term("B", "lala*")), Lucene.Net.Search.BooleanClause.Occur.MUST);
        query.Add(new WildcardQuery(new Term("C", "DoDo1*")), Lucene.Net.Search.BooleanClause.Occur.MUST);

        IndexSearcher searcher = new IndexSearcher("Test");
        Hits hits = searcher.Search(query);
        if (hits.Length() > 0)
        {
            for (int i = 0; i < hits.Length(); i++)
            {
                Console.WriteLine("{0} - {1} - {2} - {3}", 
                    hits.Doc(i).GetField("A").StringValue(),
                    hits.Doc(i).GetField("B").StringValue(),
                    hits.Doc(i).GetField("C").StringValue(),
                    hits.Doc(i).GetField("D").StringValue());
            }
        }
        searcher.Close();

        Console.WriteLine("Done");

        Console.ReadLine();
    }

I then got it to work by using MultiFieldQueryParser Like so:

    static void Main(string[] args)
    {
        StandardAnalyzer analyzer = new StandardAnalyzer();            

        IndexWriter writer = new IndexWriter("Test", analyzer, true);
        Console.WriteLine("Creating index");
        for (int i = 0; i < 1500; i++)
        {
            Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
            doc.Add(new Lucene.Net.Documents.Field("A", i.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED));
            doc.Add(new Lucene.Net.Documents.Field("B", "LALA" + i.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED));
            doc.Add(new Lucene.Net.Documents.Field("C", "DODO" + i.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED));
            doc.Add(new Lucene.Net.Documents.Field("D", i.ToString() + " MMMMM", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED));
            writer.AddDocument(doc);
        }            
        writer.Optimize();
        writer.Close();            

        BooleanQuery.SetMaxClauseCount(5000);
        Query query = MultiFieldQueryParser.Parse(new string[] { "LALA*", "DODO*" }, new string[] { "B", "C" }, analyzer); 

        IndexSearcher searcher = new IndexSearcher("Test");
        Hits hits = searcher.Search(query);
        if (hits.Length() > 0)
        {
            for (int i = 0; i < hits.Length(); i++)
            {
                Console.WriteLine("{0} - {1} - {2} - {3}", 
                    hits.Doc(i).GetField("A").StringValue(),
                    hits.Doc(i).GetField("B").StringValue(),
                    hits.Doc(i).GetField("C").StringValue(),
                    hits.Doc(i).GetField("D").StringValue());
            }
        }
        searcher.Close();

        Console.WriteLine("Done");

        Console.ReadLine();
    }

This is possibly the best article I’ve found for any new lucene developers: http://www.ifdefined.com/blog/post/2009/02/Full-Text-Search-in-ASPNET-using-LuceneNET.aspx

  • 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-13T01:36:01+00:00Added an answer on May 13, 2026 at 1:36 am

    I think there is a problem when building your index. You add four fields to each document, all of them are stored but none of them is indexed (=> Lucene.Net.Documents.Field.Index.NO). You should index at least on field.

    Beware that the StandardAnalyzer tokenize each field index in the following way: lowercasing and splitting with common english stop words. So when building your query, use LOWERCASE prefix in order to have hits:

    query.Add(new PrefixQuery(new Term("B", "lala")), BooleanClause.Occur.MUST);
    query.Add(new PrefixQuery(new Term("C", "dodo")), BooleanClause.Occur.MUST);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported

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.