Search in sources :

Example 1 with SuggesterConfig

use of org.opengrok.indexer.configuration.SuggesterConfig in project OpenGrok by OpenGrok.

the class SuggesterControllerProjectsDisabledTest method before.

@BeforeEach
public void before() {
    await().atMost(15, TimeUnit.SECONDS).until(() -> getSuggesterProjectDataSize() == 1);
    env.setSuggesterConfig(new SuggesterConfig());
}
Also used : SuggesterConfig(org.opengrok.indexer.configuration.SuggesterConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with SuggesterConfig

use of org.opengrok.indexer.configuration.SuggesterConfig in project OpenGrok by OpenGrok.

the class SuggesterServiceImpl method initSuggester.

private void initSuggester() {
    SuggesterConfig suggesterConfig = env.getSuggesterConfig();
    if (!suggesterConfig.isEnabled()) {
        logger.log(Level.INFO, "Suggester disabled");
        return;
    }
    File suggesterDir = new File(env.getDataRootPath(), IndexDatabase.SUGGESTER_DIR);
    int rebuildParalleismLevel = (int) (((float) suggesterConfig.getRebuildThreadPoolSizeInNcpuPercent() / 100) * Runtime.getRuntime().availableProcessors());
    if (rebuildParalleismLevel == 0) {
        rebuildParalleismLevel = 1;
    }
    logger.log(Level.FINER, "Suggester rebuild parallelism level: " + rebuildParalleismLevel);
    suggester = new Suggester(suggesterDir, suggesterConfig.getMaxResults(), Duration.ofSeconds(suggesterConfig.getBuildTerminationTime()), suggesterConfig.isAllowMostPopular(), env.isProjectsEnabled(), suggesterConfig.getAllowedFields(), suggesterConfig.getTimeThreshold(), rebuildParalleismLevel, Metrics.getRegistry());
    new Thread(() -> {
        suggester.init(getAllProjectIndexDirs());
        scheduleRebuild();
    }).start();
}
Also used : Suggester(org.opengrok.suggest.Suggester) File(java.io.File) SuggesterConfig(org.opengrok.indexer.configuration.SuggesterConfig)

Example 3 with SuggesterConfig

use of org.opengrok.indexer.configuration.SuggesterConfig in project OpenGrok by OpenGrok.

the class SuggesterControllerTest method testGetSuggesterConfig.

@Test
void testGetSuggesterConfig() {
    SuggesterConfig config = target(SuggesterController.PATH).path("config").request().get(SuggesterConfig.class);
    assertEquals(env.getSuggesterConfig(), config);
}
Also used : SuggesterConfig(org.opengrok.indexer.configuration.SuggesterConfig) Test(org.junit.jupiter.api.Test)

Example 4 with SuggesterConfig

use of org.opengrok.indexer.configuration.SuggesterConfig 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)

Example 5 with SuggesterConfig

use of org.opengrok.indexer.configuration.SuggesterConfig in project OpenGrok by OpenGrok.

the class SuggesterControllerTest method before.

@BeforeEach
public void before() throws InterruptedException {
    SuggesterServiceImpl.getInstance().waitForInit(15, TimeUnit.SECONDS);
    env.setSuggesterConfig(new SuggesterConfig());
}
Also used : SuggesterConfig(org.opengrok.indexer.configuration.SuggesterConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

SuggesterConfig (org.opengrok.indexer.configuration.SuggesterConfig)5 BeforeEach (org.junit.jupiter.api.BeforeEach)2 GET (jakarta.ws.rs.GET)1 Produces (jakarta.ws.rs.Produces)1 WebApplicationException (jakarta.ws.rs.WebApplicationException)1 File (java.io.File)1 Instant (java.time.Instant)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 Test (org.junit.jupiter.api.Test)1 Suggester (org.opengrok.suggest.Suggester)1 Suggestions (org.opengrok.suggest.Suggester.Suggestions)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