Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# Lucene search - build index

public class LuceneService : ILuceneService
{
    // Note there are many different types of Analyzer that may be used with Lucene, the exact one you use
    // will depend on your requirements
    private Analyzer analyzer = new WhitespaceAnalyzer(); 
    private Directory luceneIndexDirectory;
    private IndexWriter writer;
    private string indexPath = @"c:	empLuceneIndex";

    public LuceneService()
    {
        InitialiseLucene();
    }

    private void InitialiseLucene()
    {
        if(System.IO.Directory.Exists(indexPath))
        {
            System.IO.Directory.Delete(indexPath,true);
        }

        luceneIndexDirectory = FSDirectory.GetDirectory(indexPath);
        writer = new IndexWriter(luceneIndexDirectory, analyzer, true);
    }

    public void BuildIndex(IEnumerable<SampleDataFileRow> dataToIndex)
    {
        foreach (var sampleDataFileRow in dataToIndex)
	    {
		    Document doc = new Document();
            doc.Add(new Field("LineNumber", 
			sampleDataFileRow.LineNumber.ToString() , 
			Field.Store.YES, 
			Field.Index.UN_TOKENIZED));
            doc.Add(new Field("LineText", 
			sampleDataFileRow.LineText, 
			Field.Store.YES, 
			Field.Index.TOKENIZED));
            writer.AddDocument(doc);
	    }
        writer.Optimize();
        writer.Flush();
        writer.Close();
        luceneIndexDirectory.Close();
    }


    ....
    ....
    ....
    ....
    ....
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# break file into words 
Csharp :: text mesh pro 
Csharp :: how do I write to a csv file from c# using entity framework 
Csharp :: get path c# application 
Csharp :: Collision2d and Collider2d 
Csharp :: print all string in textbox in array c# 
Csharp :: convert a string to an integer without using library 
Csharp :: unity phone vibration 
Csharp :: convert relative path to physical path c# 
Csharp :: save current dir shell 
Csharp :: Custom Circular Picture Box C# win Form app 
Csharp :: c# check if pdf is protected without password 
Csharp :: c# class where T : enum 
Csharp :: unity eventtrigger blocks scrollview 
Csharp :: .net return manual status code 
Csharp :: c# silent execute exe 
Csharp :: Unity FPS camera z axis rotating problem 
Csharp :: username and password into base64 encoding c# 
Csharp :: vb.net substring after character 
Csharp :: f# list map function 
Csharp :: c# find the smallest string in an array of strings 
Csharp :: xamarin c# switch on hotspot Programmatically 
Csharp :: unity 3d animator live link 
Csharp :: can you use unity for ftee 
Csharp :: how to open or close combobox in c# 
Csharp :: trimend c# 
Csharp :: c# asqueryable select 
Csharp :: c# Windows Forms screenshot 
Csharp :: datagrid drop file wpf mvvm example 
Csharp :: initialization of dictionary in other forms c# 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =