Java Code Examples for org.apache.lucene.facet.taxonomy.TaxonomyReader#incRef()
The following examples show how to use
org.apache.lucene.facet.taxonomy.TaxonomyReader#incRef() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestDirectoryTaxonomyReader.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testOpenIfChangedAndRefCount() throws Exception { Directory dir = new ByteBuffersDirectory(); // no need for random directories here DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir); taxoWriter.addCategory(new FacetLabel("a")); taxoWriter.commit(); TaxonomyReader taxoReader = new DirectoryTaxonomyReader(dir); assertEquals("wrong refCount", 1, taxoReader.getRefCount()); taxoReader.incRef(); assertEquals("wrong refCount", 2, taxoReader.getRefCount()); taxoWriter.addCategory(new FacetLabel("a", "b")); taxoWriter.commit(); TaxonomyReader newtr = TaxonomyReader.openIfChanged(taxoReader); assertNotNull(newtr); taxoReader.close(); taxoReader = newtr; assertEquals("wrong refCount", 1, taxoReader.getRefCount()); taxoWriter.close(); taxoReader.close(); dir.close(); }
Example 2
Source File: PerfRunData.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Set the taxonomy reader. Takes ownership of that taxonomy reader, that is, * internally performs taxoReader.incRef() (If caller no longer needs that * reader it should decRef()/close() it after calling this method, otherwise, * the reader will remain open). * @param taxoReader The taxonomy reader to set. */ public synchronized void setTaxonomyReader(TaxonomyReader taxoReader) throws IOException { if (taxoReader == this.taxonomyReader) { return; } if (taxonomyReader != null) { taxonomyReader.decRef(); } if (taxoReader != null) { taxoReader.incRef(); } this.taxonomyReader = taxoReader; }