This project is read-only.

Index And Search In Files

Aug 25, 2011 at 10:37 AM

Hi. Can you show small example how to index and search in txt files using your classes. Thanks.

Feb 13, 2012 at 2:12 PM

The concept is the same as the example, the only difference being that you need to handle the reading of the text files.

            var files = Directory.GetFiles("some path", ".txt");

            var writer = new MemoryIndexWriter(true);
            var indexService = new IndexService(writer);

            var result = indexService.IndexEntities(files, f =>
            {
                return new Document()
                   .AddField(new Field("filename", f, Field.Store.YES, Field.Index.NOT_ANALYZED))
                   .AddField(new Field("contents", File.ReadAllText(f), Field.Store.YES, Field.Index.ANALYZED));
            });