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