static void LockCanBeReleased() { using (var db = new LiteDatabase(connectionString)) { StandardAnalyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30); //var directorInfo = new DirectoryInfo(Environment.CurrentDirectory + "\\indexes" ); //var directory = new SimpleFSDirectory(directorInfo); var directory = new LiteDbDirectory(db); new IndexWriter(directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), !IndexReader.IndexExists(directory), new Lucene.Net.Index.IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH)); IndexWriter indexWriter = null; while (indexWriter == null) { try { indexWriter = new IndexWriter(directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), !IndexReader.IndexExists(directory), new Lucene.Net.Index.IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH)); } catch (LockObtainFailedException) { Console.WriteLine("Lock is taken, waiting for timeout...{0}", DateTime.Now); Thread.Sleep(1000); } } } }
static void Do() { using (var db = new LiteDatabase(connectionString)) { var directory = new LiteDbDirectory(db); IndexTempData(directory); IndexSearcher searcher; var reader = DirectoryReader.Open(directory); using (new AutoStopWatch("Creating searcher")) { searcher = new IndexSearcher(reader); } using (new AutoStopWatch("Count")) Console.WriteLine("Number of docs: {0}", searcher.IndexReader.NumDocs); while (true) { SearchForPhrase(searcher, "microsoft"); Thread.Sleep(1000); //Console.WriteLine("Press a key to search again"); //Console.ReadKey(); } } }
static void Main(string[] args) { using (var db = new LiteDatabase(connectionString)) { LiteDbDirectory liteDbDirectory = new LiteDbDirectory(db); } Do(); }
static void Main(string[] args) { using (var db = new LiteDatabase(connectionString)) { LiteDbDirectory.ProvisionDatabase(db, dropExisting: true); } var t1 = Task.Factory.StartNew(Do); //var t2 = Task.Factory.StartNew(Do); //var t3 = Task.Factory.StartNew(Do); t1.Wait(); //Task.WaitAll(t1, t2, t3); }
private static void IndexTempData(LiteDbDirectory directory) { for (int outer = 0; outer < 102; outer++) { IndexWriter indexWriter = null; while (indexWriter == null) { try { indexWriter = new IndexWriter(directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), !IndexReader.IndexExists(directory), new IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH)); } catch (LockObtainFailedException) { Console.WriteLine("Lock is taken, waiting for timeout..."); Thread.Sleep(1000); } } Console.WriteLine("IndexWriter lock obtained, this process has exclusive write access to index"); indexWriter.SetRAMBufferSizeMB(500); //indexWriter.SetInfoStream(new StreamWriter(Console.OpenStandardOutput())); //indexWriter.UseCompoundFile = false; for (int iDoc = 0; iDoc < 1000; iDoc++) { //if (iDoc % 10 == 0) // Console.WriteLine(iDoc); Document doc = new Document(); doc.Add(new Field("id", DateTime.Now.ToFileTimeUtc().ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO)); doc.Add(new Field("Title", "dog " + GeneratePhrase(50), Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO)); doc.Add(new Field("Body", "dog " + GeneratePhrase(50), Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO)); indexWriter.AddDocument(doc); //GC.Collect(); } Console.WriteLine("Total docs is {0}", indexWriter.NumDocs()); Console.WriteLine("Flushing and disposing writer..."); indexWriter.Flush(true, true, true); //indexWriter.Dispose(); indexWriter.Commit(); indexWriter.Dispose(); GC.Collect(); } }
private static void IndexTempData(LiteDbDirectory directory) { for (int outer = 0; outer < 5; outer++) { IndexWriter indexWriter = null; while (indexWriter == null) { try { var analyzer = new StandardAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48); var config = new IndexWriterConfig(Lucene.Net.Util.LuceneVersion.LUCENE_48, analyzer); indexWriter = new IndexWriter(directory, config); } catch (LockObtainFailedException) { Console.WriteLine("Lock is taken, waiting for timeout..."); Thread.Sleep(1000); } } Console.WriteLine("IndexWriter lock obtained, this process has exclusive write access to index"); //indexWriter.SetInfoStream(new StreamWriter(Console.OpenStandardOutput())); //indexWriter.UseCompoundFile = false; for (int iDoc = 0; iDoc < 1000; iDoc++) { //if (iDoc % 10 == 0) // Console.WriteLine(iDoc); Document doc = new Document(); doc.Add(new StringField("id", DateTime.Now.ToFileTimeUtc().ToString(), Field.Store.YES)); doc.Add(new TextField("Title", "dog " + GeneratePhrase(50), Field.Store.YES)); doc.Add(new TextField("Body", "dog " + GeneratePhrase(50), Field.Store.NO)); indexWriter.AddDocument(doc); //GC.Collect(); } Console.WriteLine("Total docs is {0}", indexWriter.NumDocs); Console.WriteLine("Flushing and disposing writer..."); indexWriter.Flush(true, true); //indexWriter.Dispose(); indexWriter.Commit(); indexWriter.Dispose(); GC.Collect(); } }
static void Main(string[] args) { using (var db = new LiteDatabase(connectionString)) { LiteDbDirectory liteDbDirectory = new LiteDbDirectory(db); try { liteDbDirectory.CheckRequiredCollection(); } catch (ConfigurationErrorsException e) { LiteDbDirectory.CreateRequiredCollections(db, dropExisting: true); } } Do(); //var t1 = Task.Factory.StartNew(Do); //var t2 = Task.Factory.StartNew(Do); //var t3 = Task.Factory.StartNew(Do); //t1.Wait(); //Task.WaitAll(t1, t2, t3); }
static void LockCanBeReleased() { using (var db = new LiteDatabase(connectionString)) { StandardAnalyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48); var directory = new LiteDbDirectory(db); var config = new IndexWriterConfig(Lucene.Net.Util.LuceneVersion.LUCENE_48, analyzer); IndexWriter indexWriter = null; while (indexWriter == null) { try { indexWriter = new IndexWriter(directory, config); } catch (LockObtainFailedException) { Console.WriteLine("Lock is taken, waiting for timeout...{0}", DateTime.Now); Thread.Sleep(1000); } } } }
static void Do() { //var directory = new SimpleFSDirectory(new DirectoryInfo(@"c:\temp\lucene")); using (var db = new LiteDatabase(connectionString)) { var directory = new LiteDbDirectory(db); for (int outer = 0; outer < 102; outer++) { IndexWriter indexWriter = null; while (indexWriter == null) { try { indexWriter = new IndexWriter(directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), !IndexReader.IndexExists(directory), new Lucene.Net.Index.IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH)); } catch (LockObtainFailedException) { Console.WriteLine("Lock is taken, waiting for timeout..."); Thread.Sleep(1000); } } Console.WriteLine("IndexWriter lock obtained, this process has exclusive write access to index"); indexWriter.SetRAMBufferSizeMB(500); //indexWriter.SetInfoStream(new StreamWriter(Console.OpenStandardOutput())); //indexWriter.UseCompoundFile = false; for (int iDoc = 0; iDoc < 1000; iDoc++) { //if (iDoc % 10 == 0) // Console.WriteLine(iDoc); Document doc = new Document(); doc.Add(new Field("id", DateTime.Now.ToFileTimeUtc().ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO)); doc.Add(new Field("Title", "dog " + GeneratePhrase(50), Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO)); doc.Add(new Field("Body", "dog " + GeneratePhrase(50), Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO)); indexWriter.AddDocument(doc); //GC.Collect(); } Console.WriteLine("Total docs is {0}", indexWriter.NumDocs()); Console.WriteLine("Flushing and disposing writer..."); indexWriter.Flush(true, true, true); //indexWriter.Dispose(); indexWriter.Commit(); indexWriter.Dispose(); GC.Collect(); } IndexSearcher searcher; using (new AutoStopWatch("Creating searcher")) { searcher = new IndexSearcher(directory); } using (new AutoStopWatch("Count")) Console.WriteLine("Number of docs: {0}", searcher.IndexReader.NumDocs()); while (true) { SearchForPhrase(searcher, "microsoft"); Thread.Sleep(1000); //Console.WriteLine("Press a key to search again"); //Console.ReadKey(); } } }