List of usage examples for org.apache.lucene.index IndexWriter IndexWriter
public IndexWriter(Directory d, IndexWriterConfig conf) throws IOException
conf
. From source file:com.gauronit.tagmata.core.Indexer.java
License:Open Source License
public void renameIndex(String indexName, String indexDisplayName) { try {/*from ww w . j a v a2 s . com*/ IndexWriter mainIndexWriter = new IndexWriter( FSDirectory.open(new File(indexDir + File.separator + MAIN_INDEX)), new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUCENE_35))); Document doc = new Document(); doc.add(new Field("displayName", indexDisplayName, Store.YES, Index.NOT_ANALYZED)); doc.add(new Field("indexName", indexName, Store.YES, Index.NOT_ANALYZED)); mainIndexWriter.updateDocument(new Term("indexName", indexName), doc, new StandardAnalyzer(Version.LUCENE_35)); mainIndexWriter.prepareCommit(); mainIndexWriter.commit(); mainIndexWriter.close(); mainIndexWriter = null; } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.gauronit.tagmata.core.Indexer.java
License:Open Source License
public void deleteCards(ArrayList<CardSnapshot> cardSnaps) { try {// w w w .j av a 2 s . c om for (CardSnapshot cardSnap : cardSnaps) { IndexWriter writer = new IndexWriter( FSDirectory.open(new File(indexDir + File.separator + cardSnap.getIndexName())), new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUCENE_35))); writer.deleteDocuments(new Term("id", cardSnap.getId())); writer.prepareCommit(); writer.commit(); writer.close(); writer = null; } } catch (Exception ex) { } }
From source file:com.gauronit.tagmata.core.Indexer.java
License:Open Source License
public void saveCard(String title, String tags, String text, String indexName) { try {//w w w .j a v a 2s . co m IndexWriter writer = new IndexWriter(FSDirectory.open(new File(indexDir + File.separator + indexName)), new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUCENE_35))); Document doc = new Document(); doc.add(new Field("title", title, Store.YES, Index.ANALYZED)); doc.add(new Field("tags", tags, Store.YES, Index.ANALYZED)); doc.add(new Field("text", text, Store.YES, Index.ANALYZED)); doc.add(new Field("analyzedText", text, Store.YES, Index.ANALYZED)); doc.add(new Field("indexName", indexName, Store.YES, Index.ANALYZED)); doc.add(new Field("id", UUID.randomUUID().toString(), Store.YES, Index.NOT_ANALYZED)); writer.addDocument(doc, new StandardAnalyzer(Version.LUCENE_35)); writer.prepareCommit(); writer.commit(); writer.close(); writer = null; } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.gauronit.tagmata.core.Indexer.java
License:Open Source License
public void saveBookmark(String id, String indexName) { try {/*from w w w . j a v a 2 s . c o m*/ IndexWriter mainIndexWriter = new IndexWriter( FSDirectory.open(new File(indexDir + File.separator + MAIN_INDEX)), new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUCENE_35))); Document doc = new Document(); doc.add(new Field("qcId", id, Store.YES, Index.NOT_ANALYZED)); doc.add(new Field("qcIndexName", indexName, Store.YES, Index.NOT_ANALYZED)); mainIndexWriter.updateDocument(new Term("id", id), doc); mainIndexWriter.prepareCommit(); mainIndexWriter.commit(); mainIndexWriter.close(); mainIndexWriter = null; } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.gauronit.tagmata.core.Indexer.java
License:Open Source License
public void deleteBookmark(String id, String indexName) { try {/*from www . j ava2s. c o m*/ IndexWriter mainIndexWriter = new IndexWriter( FSDirectory.open(new File(indexDir + File.separator + MAIN_INDEX)), new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUCENE_35))); mainIndexWriter.deleteDocuments(new Term("qcId", id)); mainIndexWriter.prepareCommit(); mainIndexWriter.commit(); mainIndexWriter.close(); mainIndexWriter = null; } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.gauronit.tagmata.core.Indexer.java
License:Open Source License
public void updateCard(CardSnapshot cardSnap, String title, String tags, String text) { try {/*from w ww.j av a 2 s. c o m*/ IndexWriter writer = new IndexWriter( FSDirectory.open(new File(indexDir + File.separator + cardSnap.getIndexName())), new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUCENE_35))); Document doc = new Document(); doc.add(new Field("title", title, Store.YES, Index.ANALYZED)); doc.add(new Field("tags", tags, Store.YES, Index.ANALYZED)); doc.add(new Field("text", text, Store.YES, Index.ANALYZED)); doc.add(new Field("analyzedText", text, Store.YES, Index.ANALYZED)); doc.add(new Field("indexName", cardSnap.getIndexName(), Store.YES, Index.ANALYZED)); doc.add(new Field("id", cardSnap.getId(), Store.YES, Index.NOT_ANALYZED)); writer.updateDocument(new Term("id", cardSnap.getId()), doc, new StandardAnalyzer(Version.LUCENE_35)); writer.prepareCommit(); writer.commit(); writer.close(); writer = null; } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.gauronit.tagmata.core.Indexer.java
License:Open Source License
public static void main(String[] args) { try {/*from w w w.ja v a 2s . co m*/ IndexWriter writer = new IndexWriter(FSDirectory.open(new File(indexDir + File.separator + "null")), new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUCENE_35))); writer.deleteDocuments(new Term("indexName", "null")); writer.prepareCommit(); writer.commit(); writer.close(); } catch (Exception ex) { logger.log(Level.SEVERE, "Failed to Initialize", ex); } }
From source file:com.gemstone.gemfire.cache.lucene.internal.distributed.DistributedScoringJUnitTest.java
License:Apache License
private IndexRepositoryImpl createIndexRepo() throws IOException { ConcurrentHashMap<String, File> fileRegion = new ConcurrentHashMap<String, File>(); ConcurrentHashMap<ChunkKey, byte[]> chunkRegion = new ConcurrentHashMap<ChunkKey, byte[]>(); RegionDirectory dir = new RegionDirectory(fileRegion, chunkRegion); IndexWriterConfig config = new IndexWriterConfig(analyzer); IndexWriter writer = new IndexWriter(dir, config); return new IndexRepositoryImpl(region, writer, mapper); }
From source file:com.gemstone.gemfire.cache.lucene.internal.IndexRepositoryFactory.java
License:Apache License
public IndexRepository createIndexRepository(final Integer bucketId, PartitionedRegion userRegion, PartitionedRegion fileRegion, PartitionedRegion chunkRegion, LuceneSerializer serializer, Analyzer analyzer, LuceneIndexStats indexStats, FileSystemStats fileSystemStats) throws IOException { final IndexRepository repo; BucketRegion fileBucket = getMatchingBucket(fileRegion, bucketId); BucketRegion chunkBucket = getMatchingBucket(chunkRegion, bucketId); if (fileBucket == null || chunkBucket == null) { return null; }/* w w w. j av a2 s.c om*/ RegionDirectory dir = new RegionDirectory(fileBucket, chunkBucket, fileSystemStats); IndexWriterConfig config = new IndexWriterConfig(analyzer); IndexWriter writer = new IndexWriter(dir, config); repo = new IndexRepositoryImpl(fileBucket, writer, serializer, indexStats); return repo; }
From source file:com.gemstone.gemfire.cache.lucene.internal.PartitionedRepositoryManager.java
License:Apache License
/** * Return the repository for a given user bucket *//*from w w w. ja va 2s.c o m*/ private IndexRepository getRepository(Integer bucketId) throws BucketNotFoundException { IndexRepository repo = indexRepositories.get(bucketId); //Remove the repository if it has been destroyed (due to rebalancing) if (repo != null && repo.isClosed()) { indexRepositories.remove(bucketId, repo); repo = null; } if (repo == null) { try { BucketRegion fileBucket = getMatchingBucket(fileRegion, bucketId); BucketRegion chunkBucket = getMatchingBucket(chunkRegion, bucketId); RegionDirectory dir = new RegionDirectory(fileBucket, chunkBucket); IndexWriterConfig config = new IndexWriterConfig(analyzer); IndexWriter writer = new IndexWriter(dir, config); repo = new IndexRepositoryImpl(fileBucket, writer, serializer); IndexRepository oldRepo = indexRepositories.putIfAbsent(bucketId, repo); if (oldRepo != null) { repo = oldRepo; } } catch (IOException e) { throw new InternalGemFireError("Unable to create index repository", e); } } return repo; }