use of org.apache.lucene.index.IndexWriter in project gitblit by gitblit.
the class TicketIndexer method getWriter.
private IndexWriter getWriter() throws IOException {
if (writer == null) {
indexStore.create();
Directory directory = FSDirectory.open(indexStore.getPath());
StandardAnalyzer analyzer = new StandardAnalyzer();
IndexWriterConfig config = new IndexWriterConfig(analyzer);
config.setOpenMode(OpenMode.CREATE_OR_APPEND);
writer = new IndexWriter(directory, config);
}
return writer;
}
use of org.apache.lucene.index.IndexWriter in project geode by apache.
the class RawIndexRepositoryFactory method computeIndexRepository.
@Override
public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer serializer, LuceneIndexImpl index, PartitionedRegion userRegion, IndexRepository oldRepository) throws IOException {
final IndexRepository repo;
if (oldRepository != null) {
oldRepository.cleanup();
}
LuceneRawIndex indexForRaw = (LuceneRawIndex) index;
BucketRegion dataBucket = getMatchingBucket(userRegion, bucketId);
Directory dir = null;
if (indexForRaw.withPersistence()) {
String bucketLocation = LuceneServiceImpl.getUniqueIndexName(index.getName(), index.getRegionPath() + "_" + bucketId);
File location = new File(index.getName(), bucketLocation);
if (!location.exists()) {
location.mkdirs();
}
dir = new NIOFSDirectory(location.toPath());
} else {
dir = new RAMDirectory();
}
IndexWriterConfig config = new IndexWriterConfig(indexForRaw.getAnalyzer());
IndexWriter writer = new IndexWriter(dir, config);
return new IndexRepositoryImpl(null, writer, serializer, indexForRaw.getIndexStats(), dataBucket, null, "");
}
use of org.apache.lucene.index.IndexWriter in project geode by apache.
the class DumpDirectoryFilesJUnitTest method createMocks.
@Before
public void createMocks() throws BucketNotFoundException {
GemFireCacheImpl cache = Fakes.cache();
context = mock(RegionFunctionContext.class);
ResultSender sender = mock(ResultSender.class);
Region region = mock(Region.class);
InternalLuceneService service = mock(InternalLuceneService.class);
InternalLuceneIndex index = mock(InternalLuceneIndex.class);
RepositoryManager repoManager = mock(RepositoryManager.class);
IndexRepository repo = mock(IndexRepository.class);
IndexWriter writer = mock(IndexWriter.class);
RegionDirectory directory = mock(RegionDirectory.class);
fileSystem = mock(FileSystem.class);
Region bucket = mock(Region.class);
when(bucket.getFullPath()).thenReturn(bucketName);
when(context.getArguments()).thenReturn(new String[] { directoryName, indexName });
when(context.getResultSender()).thenReturn(sender);
when(context.getDataSet()).thenReturn(region);
when(region.getCache()).thenReturn(cache);
when(cache.getService(any())).thenReturn(service);
when(repoManager.getRepositories(eq(context))).thenReturn(Collections.singleton(repo));
when(index.getRepositoryManager()).thenReturn(repoManager);
when(index.getName()).thenReturn(indexName);
when(service.getIndex(eq(indexName), any())).thenReturn(index);
when(directory.getFileSystem()).thenReturn(fileSystem);
when(writer.getDirectory()).thenReturn(directory);
when(repo.getWriter()).thenReturn(writer);
when(repo.getRegion()).thenReturn(bucket);
}
use of org.apache.lucene.index.IndexWriter in project geode by apache.
the class IndexRepositoryImplJUnitTest method setUp.
@Before
public void setUp() throws IOException {
ConcurrentHashMap fileAndChunkRegion = new ConcurrentHashMap();
fileSystemStats = mock(FileSystemStats.class);
RegionDirectory dir = new RegionDirectory(fileAndChunkRegion, fileSystemStats);
IndexWriterConfig config = new IndexWriterConfig(analyzer);
writer = new IndexWriter(dir, config);
String[] indexedFields = new String[] { "s", "i", "l", "d", "f", "s2", "missing" };
mapper = new HeterogeneousLuceneSerializer(indexedFields);
region = Mockito.mock(Region.class);
userRegion = Mockito.mock(BucketRegion.class);
BucketAdvisor bucketAdvisor = Mockito.mock(BucketAdvisor.class);
Mockito.when(bucketAdvisor.isPrimary()).thenReturn(true);
Mockito.when(((BucketRegion) userRegion).getBucketAdvisor()).thenReturn(bucketAdvisor);
Mockito.when(((BucketRegion) userRegion).getBucketAdvisor().isPrimary()).thenReturn(true);
stats = Mockito.mock(LuceneIndexStats.class);
Mockito.when(userRegion.isDestroyed()).thenReturn(false);
repo = new IndexRepositoryImpl(region, writer, mapper, stats, userRegion, mock(DistributedLockService.class), "lockName");
}
use of org.apache.lucene.index.IndexWriter in project jackrabbit by apache.
the class AbstractIndex method addDocuments.
/**
* Adds documents to this index and invalidates the shared reader.
*
* @param docs the documents to add.
* @throws IOException if an error occurs while writing to the index.
*/
void addDocuments(Document[] docs) throws IOException {
final List<IOException> exceptions = Collections.synchronizedList(new ArrayList<IOException>());
final CountDownLatch latch = new CountDownLatch(docs.length);
final IndexWriter writer = getIndexWriter();
for (final Document doc : docs) {
executor.execute(new Runnable() {
public void run() {
try {
// check if text extractor completed its work
Document document = getFinishedDocument(doc);
if (log.isDebugEnabled()) {
long start = System.nanoTime();
writer.addDocument(document);
log.debug("Inverted a document in {}us", (System.nanoTime() - start) / 1000);
} else {
writer.addDocument(document);
}
} catch (IOException e) {
log.warn("Exception while inverting a document", e);
exceptions.add(e);
} finally {
latch.countDown();
}
}
});
}
for (; ; ) {
try {
latch.await();
break;
} catch (InterruptedException e) {
// retry
}
}
invalidateSharedReader();
if (!exceptions.isEmpty()) {
throw new IOExceptionWithCause(exceptions.size() + " of " + docs.length + " background indexer tasks failed", exceptions.get(0));
}
}
Aggregations