static void Main(string[] args) { // Path to index file. Directory pdfIndex = FSDirectory.Open(@"/* PASTE THE PATH WHERE YOUR INDEX WILL BE SAVED */"); // Creating analyzer to make index searchable. Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30); // Creating IndexWriter IndexWriter.MaxFieldLength mfl = new IndexWriter.MaxFieldLength(100000); IndexWriter writer = new IndexWriter(pdfIndex, analyzer, mfl); // Full path to input .pdf files. string[] filesList = System.IO.Directory.GetFiles(@"/* PASTE THE PATH TO YOUR INPUT FILE(S) */", "*.pdf"); /* INDEX FIELDS: ** id & body are the fields to my Lucene Index, ** you can change those fields accordingly to your ** needs */ int idNumber = 0; string pdfText; foreach (string file in filesList) { pdfText = GetAllText(file); AddToIndex(idNumber, pdfText, writer); idNumber++; } writer.Dispose(); DisplayAllInput(filesList); Console.ReadKey(); }
public RavenIndexWriter(Directory d, Analyzer a, IndexDeletionPolicy deletionPolicy, IndexWriter.MaxFieldLength mfl, int maximumNumberOfWritesBeforeRecreate, IndexWriter.IndexReaderWarmer indexReaderWarmer) { directory = d; analyzer = a; indexDeletionPolicy = deletionPolicy; maxFieldLength = mfl; _indexReaderWarmer = indexReaderWarmer; this.maximumNumberOfWritesBeforeRecreate = maximumNumberOfWritesBeforeRecreate; RecreateIfNecessary(); }
public RavenIndexWriter(Directory d, Analyzer a, IndexDeletionPolicy deletionPolicy, IndexWriter.MaxFieldLength mfl, int maximumNumberOfWritesBeforeRecreate, IndexWriter.IndexReaderWarmer indexReaderWarmer) { directory = d; analyzer = a; indexDeletionPolicy = deletionPolicy; maxFieldLength = mfl; _indexReaderWarmer = indexReaderWarmer; this.maximumNumberOfWritesBeforeRecreate = maximumNumberOfWritesBeforeRecreate; forceCommitDoc = new Document(); forceCommitDoc.Add(forceCommitField); RecreateIfNecessary(force: true); }
protected override void Context() { var dir = new SimpleFSDirectory(new DirectoryInfo(TempDirectory), new NoLockFactory()); var analyzer = new StandardAnalyzer(Version.LUCENE_20); var maxFieldLength = new IndexWriter.MaxFieldLength(200); var index = new FluentIndexWriter<TestObject>(dir, analyzer, maxFieldLength); var data = new TestObject() { Id = Guid.NewGuid(), LongId = 123, ValidProperty = "Property", IgnoredProperty = "Ignored" }; var data2 = new TestObject() { Id = Guid.Empty, LongId = 123456, ValidProperty = "Abc def ghij", IgnoredProperty = "Ignored" }; index.AddDocument(data); index.AddDocument(data2); index.Commit(); }
/// <summary> /// Initializes a new instance of the <see cref="SearchServiceConfiguration" /> class. /// </summary> /// <param name="luceneVersion">The lucene version.</param> /// <param name="maxFieldLength">Maximum length of the field.</param> /// <param name="indexFolder">The index folder.</param> /// <param name="writeLockSemaphoreFileName">Name of the write lock semaphore file.</param> /// <param name="hitLimit">The hit limit.</param> public SearchServiceConfiguration( Version luceneVersion, IndexWriter.MaxFieldLength maxFieldLength, string indexFolder, string writeLockSemaphoreFileName, int hitLimit) { this.luceneVersion = luceneVersion.IsNull() ? Version.LUCENE_30 : luceneVersion; this.maxFieldLength = maxFieldLength.IsNull() ? IndexWriter.MaxFieldLength.UNLIMITED : maxFieldLength; this.indexFolder = indexFolder.IsNullOrEmpty() ? @"C:\SearchIndex\" : indexFolder; this.writeLockSemaphoreFileName = writeLockSemaphoreFileName.IsNullOrEmpty() ? Path.Combine(this.indexFolder, "write.lock") : writeLockSemaphoreFileName; this.hitLimit = hitLimit.Equals(EqualityComparer<int>.Default.Equals(hitLimit, default(int))) ? 1000 : hitLimit; this.fsDirectory = this.GetDirectory(); }