Search in sources :

Example 1 with NamedIndexReader

use of org.opengrok.suggest.Suggester.NamedIndexReader in project OpenGrok by OpenGrok.

the class SuggesterServiceImpl method getSuggestions.

/**
 * {@inheritDoc}
 */
@Override
public Suggestions getSuggestions(final Collection<String> projects, final SuggesterQuery suggesterQuery, final Query query) {
    List<SuperIndexSearcher> superIndexSearchers = new LinkedList<>();
    lock.readLock().lock();
    try {
        if (suggester == null) {
            return new Suggestions(Collections.emptyList(), true);
        }
        List<NamedIndexReader> namedReaders = getNamedIndexReaders(projects, superIndexSearchers);
        return suggester.search(namedReaders, suggesterQuery, query);
    } finally {
        lock.readLock().unlock();
        for (SuperIndexSearcher s : superIndexSearchers) {
            try {
                s.getSearcherManager().release(s);
            } catch (IOException e) {
                logger.log(Level.WARNING, "Could not release " + s, e);
            }
        }
    }
}
Also used : Suggestions(org.opengrok.suggest.Suggester.Suggestions) SuperIndexSearcher(org.opengrok.indexer.configuration.SuperIndexSearcher) NamedIndexReader(org.opengrok.suggest.Suggester.NamedIndexReader) IOException(java.io.IOException) LinkedList(java.util.LinkedList)

Example 2 with NamedIndexReader

use of org.opengrok.suggest.Suggester.NamedIndexReader in project OpenGrok by OpenGrok.

the class SuggesterServiceImpl method getNamedIndexReaders.

private List<NamedIndexReader> getNamedIndexReaders(final Collection<String> projects, final List<SuperIndexSearcher> superIndexSearchers) {
    if (env.isProjectsEnabled()) {
        return projects.stream().map(project -> {
            try {
                SuperIndexSearcher searcher = env.getIndexSearcher(project);
                superIndexSearchers.add(searcher);
                return new NamedIndexReader(project, searcher.getIndexReader());
            } catch (IOException e) {
                logger.log(Level.WARNING, "Could not get index reader for " + project, e);
            }
            return null;
        }).filter(Objects::nonNull).collect(Collectors.toList());
    } else {
        SuperIndexSearcher searcher;
        try {
            searcher = env.getIndexSearcher("");
            superIndexSearchers.add(searcher);
            return Collections.singletonList(new NamedIndexReader("", searcher.getIndexReader()));
        } catch (IOException e) {
            logger.log(Level.WARNING, "Could not get index reader", e);
        }
        return Collections.emptyList();
    }
}
Also used : SuperIndexSearcher(org.opengrok.indexer.configuration.SuperIndexSearcher) NamedIndexReader(org.opengrok.suggest.Suggester.NamedIndexReader) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 SuperIndexSearcher (org.opengrok.indexer.configuration.SuperIndexSearcher)2 NamedIndexReader (org.opengrok.suggest.Suggester.NamedIndexReader)2 LinkedList (java.util.LinkedList)1 Suggestions (org.opengrok.suggest.Suggester.Suggestions)1