org.apache.lucene.index.IndexNotFoundException Java Examples

The following examples show how to use org.apache.lucene.index.IndexNotFoundException. 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: TestSearcherTaxonomyManager.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testExceptionDuringRefresh() throws Exception {

    Directory indexDir = newDirectory();
    Directory taxoDir = newDirectory();

    IndexWriter w = new IndexWriter(indexDir, newIndexWriterConfig(new MockAnalyzer(random())));
    DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir);
    w.commit();
    tw.commit();

    SearcherTaxonomyManager mgr = new SearcherTaxonomyManager(indexDir, taxoDir, null);

    tw.addCategory(new FacetLabel("a", "b"));
    w.addDocument(new Document());

    tw.commit();
    w.commit();

    // intentionally corrupt the taxo index:
    SegmentInfos infos = SegmentInfos.readLatestCommit(taxoDir);
    taxoDir.deleteFile(infos.getSegmentsFileName());
    expectThrows(IndexNotFoundException.class, mgr::maybeRefreshBlocking);
    IOUtils.close(w, tw, mgr, indexDir, taxoDir);
  }
 
Example #2
Source File: IndexReplicationHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the last {@link IndexCommit} found in the {@link Directory}, or
 * {@code null} if there are no commits.
 */
public static IndexCommit getLastCommit(Directory dir) throws IOException {
  try {
    if (DirectoryReader.indexExists(dir)) {
      List<IndexCommit> commits = DirectoryReader.listCommits(dir);
      // listCommits guarantees that we get at least one commit back, or
      // IndexNotFoundException which we handle below
      return commits.get(commits.size() - 1);
    }
  } catch (IndexNotFoundException e) {
    // ignore the exception and return null
  }
  return null;
}
 
Example #3
Source File: BaseDirectoryTestCase.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testNoDir() throws Throwable {
  Path tempDir = createTempDir("doesnotexist");
  IOUtils.rm(tempDir);
  try (Directory dir = getDirectory(tempDir)) {
    expectThrowsAnyOf(Arrays.asList(NoSuchFileException.class, IndexNotFoundException.class), () -> {
      DirectoryReader.open(dir);
    });
  }
}
 
Example #4
Source File: TestFileSwitchDirectory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testNoDir() throws Throwable {
  Path primDir = createTempDir("foo");
  Path secondDir = createTempDir("bar");
  Directory dir = newFSSwitchDirectory(primDir, secondDir, Collections.<String>emptySet());
  expectThrows(IndexNotFoundException.class, () -> {
    DirectoryReader.open(dir);
  });

  dir.close();
}
 
Example #5
Source File: TestSolrCoreSnapshots.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private List<IndexCommit> listCommits(String directory) throws Exception {
  Directory dir = new NIOFSDirectory(Paths.get(directory));
  try {
    return DirectoryReader.listCommits(dir);
  } catch (IndexNotFoundException ex) {
    // This can happen when the delete snapshot functionality cleans up the index files (when the directory
    // storing these files is not the *current* index directory).
    return Collections.emptyList();
  }
}
 
Example #6
Source File: SearcherDAO.java    From entando-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected FacetedContentsResult searchContents(SearchEngineFilter[] filters,
        Collection<ITreeNode> categories, Collection<String> allowedGroups, boolean faceted) throws ApsSystemException {
    FacetedContentsResult result = new FacetedContentsResult();
    List<String> contentsId = new ArrayList<String>();
    IndexSearcher searcher = null;
    try {
        searcher = this.getSearcher();
        Query query = null;
        if ((null == filters || filters.length == 0)
                && (null == categories || categories.isEmpty())
                && (allowedGroups != null && allowedGroups.contains(Group.ADMINS_GROUP_NAME))) {
            query = new MatchAllDocsQuery();
        } else {
            query = this.createQuery(filters, categories, allowedGroups);
        }
        TopDocs topDocs = searcher.search(query, 1000);
        ScoreDoc[] scoreDocs = topDocs.scoreDocs;
        Map<String, Integer> occurrences = new HashMap<String, Integer>();
        if (scoreDocs.length > 0) {
            for (int index = 0; index < scoreDocs.length; index++) {
                Document doc = searcher.doc(scoreDocs[index].doc);
                contentsId.add(doc.get(IIndexerDAO.DATAOBJECT_ID_FIELD_NAME));
                if (faceted) {
                    Set<String> codes = new HashSet<String>();
                    String[] categoryPaths = doc.getValues(IIndexerDAO.DATAOBJECT_CATEGORY_FIELD_NAME);
                    for (int i = 0; i < categoryPaths.length; i++) {
                        String categoryPath = categoryPaths[i];
                        String[] paths = categoryPath.split(IIndexerDAO.DATAOBJECT_CATEGORY_SEPARATOR);
                        codes.addAll(Arrays.asList(paths));
                    }
                    Iterator<String> iter = codes.iterator();
                    while (iter.hasNext()) {
                        String code = iter.next();
                        Integer value = occurrences.get(code);
                        if (null == value) {
                            value = 0;
                        }
                        occurrences.put(code, (value + 1));
                    }
                }
            }
        }
        result.setOccurrences(occurrences);
        result.setContentsId(contentsId);
    } catch (IndexNotFoundException inf) {
        logger.error("no index was found in the Directory", inf);
    } catch (Throwable t) {
        logger.error("Error extracting documents", t);
        throw new ApsSystemException("Error extracting documents", t);
    } finally {
        this.releaseResources(searcher);
    }
    return result;
}