Java Code Examples for org.apache.lucene.index.IndexReader#indexExists()
The following examples show how to use
org.apache.lucene.index.IndexReader#indexExists() .
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: IndexInfo.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private IndexReader buildAndRegisterDeltaReader(String id) throws IOException { IndexReader reader; // only register on write to avoid any locking for transactions that only ever read File location = getDeltaLocation(id); // File location = ensureDeltaIsRegistered(id); // Create a dummy index reader to deal with empty indexes and not // persist these. if (IndexReader.indexExists(location)) { reader = IndexReader.open(location); } else { reader = IndexReader.open(emptyIndex); } return reader; }
Example 2
Source File: IndexInfo.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private IndexReader buildReferenceCountingIndexReader(String id, long size) throws IOException { IndexReader reader; File location = new File(indexDirectory, id).getCanonicalFile(); double folderSize = getSizeInMb(location); if (IndexReader.indexExists(location)) { if ((size < maxDocsForInMemoryIndex) && (folderSize < maxRamInMbForInMemoryIndex)) { RAMDirectory rd = new RAMDirectory(location); reader = IndexReader.open(rd); } else { reader = IndexReader.open(location); } } else { reader = IndexReader.open(emptyIndex); } reader = ReferenceCountingReadOnlyIndexReaderFactory.createReader(id, reader, true, config); return reader; }
Example 3
Source File: AutoCompleter.java From webdsl with Apache License 2.0 | 6 votes |
/** * Use a different index as the auto completer index or re-open * the existing index if <code>autocompleteIndex</code> is the same value * as given in the constructor. * @param autocompleteIndexDir the autocomplete directory to use * @throws AlreadyClosedException if the Autocompleter is already closed * @throws IOException if autocompleter can not open the directory */ // TODO: we should make this final as it is called in the constructor public void setAutoCompleteIndex(Directory autocompleteIndexDir) throws IOException { // this could be the same directory as the current autocompleteIndex // modifications to the directory should be synchronized synchronized (modifyCurrentIndexLock) { ensureOpen(); if (!IndexReader.indexExists(autocompleteIndexDir)) { IndexWriter writer = new IndexWriter(autocompleteIndexDir, new IndexWriterConfig(Version.LUCENE_CURRENT, new WhitespaceAnalyzer(Version.LUCENE_CURRENT))); writer.close(); } swapSearcher(autocompleteIndexDir); } }
Example 4
Source File: LuceneContentSvcImpl.java From Lottery with GNU General Public License v2.0 | 6 votes |
@Transactional(readOnly = true) public Integer createIndex(Integer siteId, Integer channelId, Date startDate, Date endDate, Integer startId, Integer max, Directory dir) throws IOException, ParseException { boolean exist = IndexReader.indexExists(dir); IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer( Version.LUCENE_30), !exist, IndexWriter.MaxFieldLength.LIMITED); try { if (exist) { LuceneContent.delete(siteId, channelId, startDate, endDate, writer); } Integer lastId = luceneContentDao.index(writer, siteId, channelId, startDate, endDate, startId, max); writer.optimize(); return lastId; } finally { writer.close(); } }
Example 5
Source File: SearchServiceImpl.java From olat with Apache License 2.0 | 5 votes |
/** * Check if index exist. * * @return true : Index exists. */ private boolean existIndex() throws IOException { try { final File indexFile = new File(searchModuleConfig.getFullIndexPath()); final Directory directory = FSDirectory.open(indexFile); return IndexReader.indexExists(directory); } catch (final IOException e) { throw e; } }
Example 6
Source File: Index.java From olat with Apache License 2.0 | 5 votes |
/** * Check if index exist. * * @return true : Index exists. */ public boolean existIndex() { try { final File indexFile = new File(indexPath); final Directory directory = FSDirectory.open(indexFile); return IndexReader.indexExists(directory); } catch (final IOException e) { log.error("", e); return false; } }
Example 7
Source File: Index.java From olat with Apache License 2.0 | 5 votes |
/** * @return <code>true</code> if Lucene index exists. */ public boolean existIndex() { try { final File indexDir = new File(searchModule.getSearchIndexPath()); final Directory indexLuceneDirectory = FSDirectory.open(indexDir); return IndexReader.indexExists(indexLuceneDirectory); } catch (final IOException e) { return false; } }
Example 8
Source File: Index.java From olat with Apache License 2.0 | 5 votes |
private void createIndexSearcher(boolean indexNewlyBuilt) { try { log.info("Create searcher on new index ..."); Directory searchIndexDirectory = null; synchronized (createIndexSearcherLock) { closeIndexSearcher(); if (indexNewlyBuilt) { replaceIndexFiles(); } searchIndexDirectory = FSDirectory.open(new File(searchModule.getSearchIndexPath())); if (!IndexReader.indexExists(searchIndexDirectory)) { log.error("SpellChecker index does not exist [" + searchModule.getSearchIndexPath() + "]"); return; } searcher = new IndexSearcher(searchIndexDirectory); } final long indexTime = IndexReader.getCurrentVersion(searchIndexDirectory); if ((System.currentTimeMillis() - indexTime) > maxIndexTime) { log.error("Search index is too old [indexDate=" + new Date(indexTime) + "]."); } if (indexNewlyBuilt) { log.info("Cleanup old index files ..."); cleanupIndexFiles(); } } catch (IOException ex) { log.error("Searcher couldn't be created.", ex); } }
Example 9
Source File: Index.java From olat with Apache License 2.0 | 5 votes |
private void createSpellCheckSearcher(boolean indexNewlyBuilt) { try { log.info("Create spell checker on new index ..."); synchronized (createSpellCheckSearcherLock) {// o_clusterOK by:pb if service is only configured on one vm, which is recommended way closeSpellCheckSearcher(); if (indexNewlyBuilt) { replaceSpellCheckFiles(); } final File spellDictionaryFile = new File(searchModule.getSpellCheckerIndexPath()); final Directory spellIndexDirectory = FSDirectory.open(spellDictionaryFile); if (!IndexReader.indexExists(spellIndexDirectory)) { log.error("SpellChecker index does not exist [" + spellDictionaryFile.getAbsolutePath() + "]"); return; } spellChecker = new SpellChecker(spellIndexDirectory); spellChecker.setAccuracy(0.7f); } if (indexNewlyBuilt) { log.info("Cleanup old spell checker index files ..."); cleanupSpellCheckFiles(); } } catch (IOException ex) { log.error("SpellChecker couldn't be created.", ex); } }
Example 10
Source File: LuceneContentSvcImpl.java From Lottery with GNU General Public License v2.0 | 5 votes |
@Transactional(readOnly = true) public void createIndex(Content content, Directory dir) throws IOException { boolean exist = IndexReader.indexExists(dir); IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer( Version.LUCENE_30), !exist, IndexWriter.MaxFieldLength.LIMITED); try { writer.addDocument(LuceneContent.createDocument(content)); } finally { writer.close(); } }
Example 11
Source File: LuceneContentSvcImpl.java From Lottery with GNU General Public License v2.0 | 5 votes |
@Transactional(readOnly = true) public void deleteIndex(Integer contentId, Directory dir) throws IOException, ParseException { boolean exist = IndexReader.indexExists(dir); if (exist) { IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer( Version.LUCENE_30), false, IndexWriter.MaxFieldLength.LIMITED); try { LuceneContent.delete(contentId, writer); } finally { writer.close(); } } }
Example 12
Source File: LuceneContentSvcImpl.java From Lottery with GNU General Public License v2.0 | 5 votes |
public void updateIndex(Content content, Directory dir) throws IOException, ParseException { boolean exist = IndexReader.indexExists(dir); IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer( Version.LUCENE_30), !exist, IndexWriter.MaxFieldLength.LIMITED); try { if (exist) { LuceneContent.delete(content.getId(), writer); } writer.addDocument(LuceneContent.createDocument(content)); } finally { writer.close(); } }