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);
}
}
}
}
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();
}
}
Aggregations