use of org.opengrok.suggest.Suggester.Suggestions 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.Suggestions in project OpenGrok by OpenGrok.
the class SuggesterController method getSuggestions.
/**
* Returns suggestions based on the search criteria specified in {@code data}.
* @param data suggester form data
* @return list of suggestions and other related information
* @throws ParseException if the Lucene query created from {@code data} could not be parsed
*/
@GET
@Authorized
@CorsEnable
@Produces(MediaType.APPLICATION_JSON)
public Result getSuggestions(@Valid @BeanParam final SuggesterQueryData data) throws ParseException {
Instant start = Instant.now();
SuggesterData suggesterData = SuggesterQueryDataParser.parse(data);
if (suggesterData.getSuggesterQuery() == null) {
throw new ParseException("Could not determine suggester query");
}
SuggesterConfig config = env.getSuggesterConfig();
modifyDataBasedOnConfiguration(suggesterData, config);
if (!satisfiesConfiguration(suggesterData, config)) {
logger.log(Level.FINER, "Suggester request with data {0} does not satisfy configuration settings", data);
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
Suggestions suggestions = suggester.getSuggestions(suggesterData.getProjects(), suggesterData.getSuggesterQuery(), suggesterData.getQuery());
Instant end = Instant.now();
long timeInMs = Duration.between(start, end).toMillis();
return new Result(suggestions.getItems(), suggesterData.getIdentifier(), suggesterData.getSuggesterQueryFieldText(), timeInMs, suggestions.isPartialResult());
}
Aggregations