Ejemplo n.º 1
0
        public virtual void TestReferenceDecrementIllegally([ValueSource(typeof(ConcurrentMergeSchedulerFactories), "Values")] Func <IConcurrentMergeScheduler> newScheduler)
        {
            Directory dir    = NewDirectory();
            var       config = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))
                               .SetMergeScheduler(newScheduler());
            IndexWriter     writer = new IndexWriter(dir, config);
            SearcherManager sm     = new SearcherManager(writer, false, new SearcherFactory());

            writer.AddDocument(new Document());
            writer.Commit();
            sm.MaybeRefreshBlocking();

            IndexSearcher acquire  = sm.Acquire();
            IndexSearcher acquire2 = sm.Acquire();

            sm.Release(acquire);
            sm.Release(acquire2);

            acquire = sm.Acquire();
            acquire.IndexReader.DecRef();
            sm.Release(acquire);

            Assert.Throws <InvalidOperationException>(() => sm.Acquire(), "acquire should have thrown an InvalidOperationException since we modified the refCount outside of the manager");

            // sm.Dispose(); -- already closed
            writer.Dispose();
            dir.Dispose();
        }
Ejemplo n.º 2
0
        public IEnumerable <LuceneSearchEntry> ExecuteQuery(string indexFolder, LSearch.Query query)
        {
            var searchIndex   = LStore.FSDirectory.Open(indexFolder);
            var searchManager = new LSearch.SearcherManager(searchIndex, null);

            // try to release locs
            searchManager.MaybeRefreshBlocking();

            //execute search
            var searcher   = searchManager.Acquire();
            var rawResults = searcher.Search(query, 20);

            //convert raw results to model
            var outResults = new List <LuceneSearchEntry>();

            for (var i = 0; i < rawResults.ScoreDocs.Length; i++)
            {
                var result = rawResults.ScoreDocs[i];
                var doc    = searcher.Doc(result.Doc);

                outResults.Add(new LuceneSearchEntry
                {
                    Rank    = i,
                    Id      = doc.Get("id"),
                    Uri     = doc.Get("uri"),
                    Title   = doc.Get("title"),
                    Snippet = doc.Get("snippet"),
                    Score   = result.Score
                });
            }

            return(outResults);
        }
Ejemplo n.º 3
0
        public virtual void TestReferenceDecrementIllegally()
        {
            Directory       dir    = NewDirectory();
            IndexWriter     writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMergeScheduler(new ConcurrentMergeScheduler()));
            SearcherManager sm     = new SearcherManager(writer, false, new SearcherFactory());

            writer.AddDocument(new Document());
            writer.Commit();
            sm.MaybeRefreshBlocking();

            IndexSearcher acquire  = sm.Acquire();
            IndexSearcher acquire2 = sm.Acquire();

            sm.Release(acquire);
            sm.Release(acquire2);

            acquire = sm.Acquire();
            acquire.IndexReader.DecRef();
            sm.Release(acquire);
            try
            {
                sm.Acquire();
                Assert.Fail("acquire should have thrown an InvalidOperationException since we modified the refCount outside of the manager");
            }
            catch (InvalidOperationException ex)
            {
                //
            }

            // sm.Dispose(); -- already closed
            writer.Dispose();
            dir.Dispose();
        }
Ejemplo n.º 4
0
 public override void Run()
 {
     try
     {
         // this used to not release the lock, preventing other threads from obtaining it.
         sm.MaybeRefreshBlocking();
     }
     catch (Exception e)
     {
         throw new Exception(e.ToString(), e);
     }
 }
Ejemplo n.º 5
0
 public override void Run()
 {
     try
     {
         // this used to not release the lock, preventing other threads from obtaining it.
         sm.MaybeRefreshBlocking();
     }
     catch (Exception e) when(e.IsException())
     {
         throw RuntimeException.Create(e);
     }
 }
Ejemplo n.º 6
0
 public virtual void TestListenerCalled()
 {
     Directory dir = NewDirectory();
     IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null));
     AtomicBoolean afterRefreshCalled = new AtomicBoolean(false);
     SearcherManager sm = new SearcherManager(iw, false, new SearcherFactory());
     sm.AddListener(new RefreshListenerAnonymousInnerClassHelper(this, afterRefreshCalled));
     iw.AddDocument(new Document());
     iw.Commit();
     Assert.IsFalse(afterRefreshCalled.Get());
     sm.MaybeRefreshBlocking();
     Assert.IsTrue(afterRefreshCalled.Get());
     sm.Dispose();
     iw.Dispose();
     dir.Dispose();
 }