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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:34:03+00:00 2026-05-15T23:34:03+00:00

I have a forum like web application written in Asp.net MVC. I’m trying to

  • 0

I have a forum like web application written in Asp.net MVC. I’m trying to implement Lucene.net as the search engine. When I build my index, every now and then I get exceptions related to Lucene not being able to rename the deletable file. I think it’s because I empty the index every time I want to rebuild it. Here is the code that deals with indexing:

public class SearchService : ISearchService
{
    Directory   IndexFileLocation;
    IndexWriter Writer;
    IndexReader Reader; 
    Analyzer    Analyzer;

    public SearchService(String indexLocation)
    {
        IndexFileLocation = FSDirectory.GetDirectory(indexLocation, System.IO.Directory.Exists(indexLocation) == false);
        Reader            = IndexReader.Open(IndexFileLocation);
        Writer            = new IndexWriter(IndexFileLocation, Analyzer, IndexFileLocation.List().Length == 0);
        Analyzer          = new StandardAnalyzer();
    }

    public void ClearIndex()
    {
        var DocumentCount = Writer.DocCount();
        if (DocumentCount == 0)
            return;

        for (int i = 0; i < DocumentCount; i++)
            Reader.DeleteDocument(i);
    }

    public void AddToSearchIndex(ISearchableData Data)
    {
        Document Doc = new Document();

        foreach (var Entry in Data)
        {
            Field field = new Field(Entry.Key, 
                                    Entry.Value, 
                                    Lucene.Net.Documents.Field.Store.NO, 
                                    Lucene.Net.Documents.Field.Index.TOKENIZED, 
                                    Lucene.Net.Documents.Field.TermVector.WITH_POSITIONS_OFFSETS);
            Doc.Add(field);
        }

        Field KeyField = new Field(
            SearchField.Key.ToString(), 
            Data.Key, 
            Lucene.Net.Documents.Field.Store.YES, 
            Lucene.Net.Documents.Field.Index.NO);

        Doc.Add(KeyField);
        Writer.AddDocument(Doc);
    }

    public void Dispose()
    {
        Writer.Optimize();
        Writer.Close();
        Reader.Close();
    }
}

And here is the code that executes it all:

    private void btnRebuildIndex_Click(object sender, EventArgs e)
    {
        using (var SearchService = new SearchService(Application.StartupPath + @"\indexs\"))
        {
            SearchService.ClearIndex();
        }

        using (var SearchService = new SearchService(Application.StartupPath + @"\indexs\"))
        {
            Int32 BatchSize = 50;
            Int32 Current = 0;
            var TotalQuestions = SubmissionService.GetQuestionsCount();

            while (Current < TotalQuestions)
            {
                var Questions = SubmissionService.ListQuestions(Current, BatchSize, "Id", Qsparx.SortOrder.Asc);

                foreach (var Question in Questions)
                {
                    SearchService.AddToSearchIndex(Question.ToSearchableData());
                }

                Current += BatchSize;
            }
        }
    }

Why does Lucene complain about renaming the “deletable” file?

  • 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-15T23:34:04+00:00Added an answer on May 15, 2026 at 11:34 pm

    It turned out, if no index files exist, then creating an IndexReader before an IndexWriter is not a good idea. I also realized even though the AddDocument method of IndexWriter has two overloads (one w/ and one w/o Analyzer parameter) only the one with analyzer parameter works for me.

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

Sidebar

Related Questions

I have a fairly simple data audit web application written with ASP MVC which
I have enabled form authentication in my ASP.NET MVC web application. I want to
I have written an ASP.NET MVC application that allows the user to specify their
I have a pretty simple ASP.NET Web Form that looks a bit like the
I am trying to develop the single page in asp.net web mobile application as
I have an asp.net web-from application which uses ASP.NET membership provider . Beside this
I have just written a Word Document creation web application using .NET 3.5 which
Im creating forum like application and I have textbox where users can enter tags
I have an ASP.Net application. It is an application where people fill out forms.
My application I have an application design that looks like this: web application layer

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.