本文整理汇总了Java中org.apache.lucene.search.NRTManager类的典型用法代码示例。如果您正苦于以下问题:Java NRTManager类的具体用法?Java NRTManager怎么用?Java NRTManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NRTManager类属于org.apache.lucene.search包,在下文中一共展示了NRTManager类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIndexerMap
import org.apache.lucene.search.NRTManager; //导入依赖的package包/类
private synchronized Map<String, ItemIndex<? extends FreetextResult>> getIndexerMap()
{
Map<String, ItemIndex<? extends FreetextResult>> indexerMap = indexTracker.getBeanMap();
if( !indexesHaveBeenInited )
{
// This simply exists in order to reset the indices for the first
// time.
IndexBuilder resetBuilder = new IndexBuilder()
{
@Override
public long buildIndex(NRTManager nrtManager) throws Exception
{
return nrtManager.getCurrentSearchingGen(true);
}
};
for( ItemIndex<? extends FreetextResult> itemIndex : indexerMap.values() )
{
itemIndex.modifyIndex(resetBuilder);
}
indexesHaveBeenInited = true;
}
return indexerMap;
}
示例2: addDocuments
import org.apache.lucene.search.NRTManager; //导入依赖的package包/类
@Override
public long addDocuments(Collection<IndexedItem> documents, NRTManager nrtManager)
{
long generation = -1;
for( IndexedItem item : documents )
{
if( item.isAdd() )
{
List<Document> docs = getDocuments(item);
if( docs != null )
{
for( Document doc : docs )
{
try
{
long g = nrtManager.addDocument(doc);
if( item.isNewSearcherRequired() )
{
generation = g;
}
}
catch( IOException e )
{
throw new RuntimeException(e);
}
}
}
}
}
return generation;
}
示例3: removeDocuments
import org.apache.lucene.search.NRTManager; //导入依赖的package包/类
protected long removeDocuments(Collection<IndexedItem> documents, NRTManager nrtManager)
{
long generation = -1;
for( IndexedItem item : documents )
{
ItemIdKey itemId = item.getItemIdKey();
String unique = ItemId.fromKey(itemId).toString();
try
{
BooleanQuery delQuery = new BooleanQuery();
delQuery.add(new TermQuery(new Term(FreeTextQuery.FIELD_ID, Long.toString(itemId.getKey()))),
Occur.MUST);
delQuery.add(
new TermQuery(new Term(FreeTextQuery.FIELD_INSTITUTION, Long.toString(item.getInstitution()
.getUniqueId()))), Occur.MUST);
long g = nrtManager.deleteDocuments(delQuery);
if( item.isNewSearcherRequired() )
{
generation = g;
}
}
catch( IOException e )
{
LOGGER.error("An error occurred while attempting to delete item " + unique, e); //$NON-NLS-1$
throw new RuntimeException(e);
}
}
return generation;
}
示例4: addDocuments
import org.apache.lucene.search.NRTManager; //导入依赖的package包/类
public long addDocuments(Collection<IndexedItem> documents, NRTManager nrtManager)
{
long generation = -1;
for( IndexedItem item : documents )
{
if( item.isAdd() )
{
synchronized( item )
{
Document doc = item.getItemdoc();
if( doc.getFields().isEmpty() )
{
LOGGER.error("Trying to add an empty document for item:" + item.getId());
continue;
}
try
{
long g = nrtManager.addDocument(doc);
if( item.isNewSearcherRequired() )
{
generation = g;
}
}
catch( IOException e )
{
throw new RuntimeException(e);
}
}
}
}
return generation;
}
示例5: indexBatch
import org.apache.lucene.search.NRTManager; //导入依赖的package包/类
public void indexBatch(final Collection<IndexedItem> batch)
{
modifyIndex(new IndexBuilder()
{
@Override
public long buildIndex(NRTManager nrtManager) throws Exception
{
long generation = -1;
generation = Math.max(generation, removeDocuments(batch, nrtManager));
generation = Math.max(generation, addDocuments(batch, nrtManager));
return generation;
}
});
}
示例6: deleteForInstitution
import org.apache.lucene.search.NRTManager; //导入依赖的package包/类
public void deleteForInstitution(final long id)
{
modifyIndex(new IndexBuilder()
{
@Override
public long buildIndex(NRTManager nrtManager) throws Exception
{
nrtManager.deleteDocuments(new Term(FreeTextQuery.FIELD_INSTITUTION, Long.toString(id)));
return -1;
}
});
}
示例7: LuceneIndexer
import org.apache.lucene.search.NRTManager; //导入依赖的package包/类
public LuceneIndexer(String indexName) throws IOException {
this.indexName = indexName;
luceneWriterService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(),
new NamedThreadFactory(threadGroup, indexName + " Lucene writer"));
luceneWriterFutureCheckerService = Executors.newFixedThreadPool(1,
new NamedThreadFactory(threadGroup, indexName + " Lucene future checker"));
setupRoot();
File indexDirectoryFile = new File(root.getPath() + "/" + indexName);
System.out.println("Index: " + indexDirectoryFile);
Directory indexDirectory = initDirectory(indexDirectoryFile);
indexDirectory.clearLock("write.lock");
IndexWriterConfig config = new IndexWriterConfig(luceneVersion, new StandardAnalyzer(luceneVersion));
MergePolicy mergePolicy = new LogByteSizeMergePolicy();
config.setMergePolicy(mergePolicy);
config.setSimilarity(new ShortTextSimilarity());
IndexWriter indexWriter = new IndexWriter(indexDirectory, config);
trackingIndexWriter = new NRTManager.TrackingIndexWriter(indexWriter);
boolean applyAllDeletes = false;
searcherManager = new NRTManager(trackingIndexWriter, null, applyAllDeletes);
// Refreshes searcher every 5 seconds when nobody is waiting, and up to 100 msec delay
// when somebody is waiting:
reopenThread = new NRTManagerReopenThread(searcherManager, 5.0, 0.1);
this.startThread();
}
示例8: testNrtManager
import org.apache.lucene.search.NRTManager; //导入依赖的package包/类
@Test
public void testNrtManager() throws IOException {
TrackingIndexWriter trackingIndexWriter = new TrackingIndexWriter(indexWriter);
NRTManager nrtManager = new NRTManager(trackingIndexWriter, new SearcherFactory());
IndexSearcher indexSearcher = null;
try {
indexSearcher = nrtManager.acquire();
}
finally {
if (indexSearcher == null) {
nrtManager.release(indexSearcher);
}
}
}
示例9: afterPropertiesSet
import org.apache.lucene.search.NRTManager; //导入依赖的package包/类
@PostConstruct
public void afterPropertiesSet() throws IOException
{
if( !indexPath.exists() )
{
if( !indexPath.mkdirs() )
{
throw new Error("Error creating index:" + indexPath); //$NON-NLS-1$
}
}
directory = FSDirectory.open(indexPath);
if( IndexWriter.isLocked(directory) )
{
LOGGER.info("Unlocking index:" + indexPath); //$NON-NLS-1$
IndexWriter.unlock(directory);
}
LOGGER.info("Opening writer for index:" + indexPath); //$NON-NLS-1$
indexWriter = new IndexWriter(directory, new IndexWriterConfig(LuceneConstants.LATEST_VERSION, getAnalyser()));
nrtManager = new NRTManager(indexWriter, null);
// Possibly reopen a searcher every 5 seconds if necessary in the
// background
nrtReopenThread = new NRTManagerReopenThread(nrtManager, 5.0, 0.1);
nrtReopenThread.setName("NRT Reopen Thread: " + getClass());
nrtReopenThread.setPriority(Math.min(Thread.currentThread().getPriority() + 2, Thread.MAX_PRIORITY));
nrtReopenThread.setDaemon(true);
nrtReopenThread.start();
// Commit any changes to disk every 5 minutes
commiterThread = new Timer(true);
commiterThread.schedule(new TimerTask()
{
@Override
public void run()
{
try
{
indexWriter.commit();
}
catch( IOException ex )
{
LOGGER.error("Error attempting to commit index writer", ex);
}
}
}, 5 * 60 * 1000, 5 * 60 * 1000);
}
示例10: buildIndex
import org.apache.lucene.search.NRTManager; //导入依赖的package包/类
/**
* @return The index generation to wait for, or -1 if you don't care.
*/
long buildIndex(NRTManager nrtManager) throws Exception;