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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:32:47+00:00 2026-05-25T17:32:47+00:00

add index code: public class IndexManage { public static void AddIndex(List<QuestionItem> itemList) { Analyzer

  • 0

add index code:

public class IndexManage
{
    public static void AddIndex(List<QuestionItem> itemList)
    {
        Analyzer analyzer =new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
        Lucene.Net.Store.FSDirectory fs = Lucene.Net.Store.FSDirectory.Open(new DirectoryInfo("IndexDirectory"));
        IndexWriter writer =new IndexWriter(fs, analyzer,true,IndexWriter.MaxFieldLength.UNLIMITED);
        foreach (var item in itemList)
        {
            AddDocument(writer, item);
        }
        writer.Commit();
        writer.Optimize();
        writer.Close();
    }

    private static void AddDocument(IndexWriter writer, QuestionItem item)
    {
        Document document =new Document();
        document.Add(new Field("qid", item.QID.ToString(), Field.Store.YES, Field.Index.ANALYZED));
        document.Add(new Field("title", item.Title, Field.Store.YES,Field.Index.ANALYZED));
        document.Add(new Field("content", item.Content, Field.Store.YES, Field.Index.ANALYZED));
        document.Add(new Field("supply", item.Supply, Field.Store.YES, Field.Index.ANALYZED));
        writer.AddDocument(document);
    }
}

search code:

public class SearchManage
    {
        public static List<QuestionItem> Search(string keyword)
        {
            Analyzer analyzer =new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
            Lucene.Net.Store.FSDirectory fs = Lucene.Net.Store.FSDirectory.Open(new DirectoryInfo("IndexDirectory"));
            IndexSearcher searcher =new IndexSearcher(fs,true);
            MultiFieldQueryParser parser =new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29,new string[] { "title", "content","supply" }, analyzer);
            parser.SetDefaultOperator(QueryParser.Operator.OR);
            Query query = parser.Parse(keyword);

            var hits = searcher.Search(query, 2500);
            List<QuestionItem> itemList =new List<QuestionItem>();
            for (int i =0; i < hits.scoreDocs.Length; i++)
            {
                var doc =searcher.Doc ( hits.scoreDocs[i].doc);
                itemList.Add(new QuestionItem() { 
                    QID=Int32.Parse(doc.Get("qid")),
                    Title=doc.Get("title"),
                    Content=doc.Get("content"),
                    Supply=doc.Get("supply")
                });
            }
            searcher.Close();
            return itemList;
        }
    }

QuestionItem model is:

public class QuestionItem
{
    public int QID { get;set; }
    public string Title{get;set;}
    public string Content { get; set; }
    public string Supply { get; set; }
}

Test code is:

public static void Show()
{
    AddIndex();
    List<QuestionItem> itemList = SearchManage.Search("a");
    Console.WriteLine("search result:");
    foreach (var item in itemList)
    {
        Console.WriteLine(item.QID +""+ item.Title +""+ item.Content +""+ item.Supply);
    }
}

private static void AddIndex()
{
    List<QuestionItem> itemList =new List<QuestionItem>() {
        new QuestionItem(){QID=1,Title="a",Content="ab",Supply="abc"},
        new QuestionItem(){QID=2,Title="b",Content="a",Supply="fds a"},
        new QuestionItem(){QID=3,Title="c",Content="c defg",Supply="as dfg hjk"},
        new QuestionItem(){QID=4,Title="d",Content="def a b",Supply="kjhgf ds a"},
        new QuestionItem(){QID=5,Title="e",Content="ef ab c",Supply="a sdf g hjkl"}
    };
    IndexManage.AddIndex(itemList);
}

now the problem is :
search “a”, no results, but for the “ab”, “b”, “c” have outcome ,a very strange problem, who can help me?

  • 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-25T17:32:48+00:00Added an answer on May 25, 2026 at 5:32 pm

    StandardAnalyzer uses a list of default stop words of which one is ‘a’. If you didn’t want stop words you could use the constructor with an empty set as the second argument:

    Analyzer ana = new StandardAnalyzer(LUCENE_30, Collections.emptySet());
    

    or in .net like this:

    Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29, new Hashtable());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code public class BaseController : Controller { SqlConnection con; DataSet
The following is an extract from my code: public class AllIntegerIDs { public AllIntegerIDs()
I'd like to add an index to a table that already contains data. I
The MySQL documentation isn't very clear on this. I want to add an index
Why does the Add method on the NameObjectCollectionBase insert at index position 0? Is
I added a file to the index with: git add somefile.txt I then got
I've added a file to the 'index' with: git add myfile.java How do I
When I create a view different from index action (for example the action video/add)
I have a Lucene index which is currently case sensitive. I want to add
I have a UITableView with an Index on the side; I want to add

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.