Search in sources :

Example 1 with Suggestions

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);
            }
        }
    }
}
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 Suggestions

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());
}
Also used : Suggestions(org.opengrok.suggest.Suggester.Suggestions) WebApplicationException(jakarta.ws.rs.WebApplicationException) Instant(java.time.Instant) ParseException(org.apache.lucene.queryparser.classic.ParseException) SuggesterData(org.opengrok.web.api.v1.suggester.model.SuggesterData) SuggesterConfig(org.opengrok.indexer.configuration.SuggesterConfig) CorsEnable(org.opengrok.web.api.v1.filter.CorsEnable) Authorized(org.opengrok.web.api.v1.suggester.provider.filter.Authorized) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET)

Aggregations

Suggestions (org.opengrok.suggest.Suggester.Suggestions)2 GET (jakarta.ws.rs.GET)1 Produces (jakarta.ws.rs.Produces)1 WebApplicationException (jakarta.ws.rs.WebApplicationException)1 IOException (java.io.IOException)1 Instant (java.time.Instant)1 LinkedList (java.util.LinkedList)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 SuggesterConfig (org.opengrok.indexer.configuration.SuggesterConfig)1 SuperIndexSearcher (org.opengrok.indexer.configuration.SuperIndexSearcher)1 NamedIndexReader (org.opengrok.suggest.Suggester.NamedIndexReader)1 CorsEnable (org.opengrok.web.api.v1.filter.CorsEnable)1 SuggesterData (org.opengrok.web.api.v1.suggester.model.SuggesterData)1 Authorized (org.opengrok.web.api.v1.suggester.provider.filter.Authorized)1