use of org.opengrok.web.api.v1.suggester.query.SuggesterQueryBuilder in project OpenGrok by OpenGrok.
the class SuggesterQueryDataParser method parse.
/**
* Parses the {@link SuggesterQueryData}.
* @param data data to parse
* @return parsed data for the suggester use
* @throws ParseException could not parse the search data into a valid {@link Query}
*/
public static SuggesterData parse(final SuggesterQueryData data) throws ParseException {
List<String> projectList = data.getProjects().stream().filter(p -> RuntimeEnvironment.getInstance().getProjectNames().contains(p)).collect(Collectors.toList());
Map<String, String> fieldQueries = getFieldQueries(data);
ProcessedQueryData queryData = processQuery(fieldQueries.get(data.getField()), data.getCaretPosition());
fieldQueries.put(data.getField(), queryData.query);
SuggesterQueryBuilder builder = new SuggesterQueryBuilder(data.getField(), queryData.identifier);
builder.setFreetext(fieldQueries.get(QueryBuilder.FULL)).setDefs(fieldQueries.get(QueryBuilder.DEFS)).setRefs(fieldQueries.get(QueryBuilder.REFS)).setPath(fieldQueries.get(QueryBuilder.PATH)).setHist(fieldQueries.get(QueryBuilder.HIST)).setType(fieldQueries.get(QueryBuilder.TYPE));
Query query;
try {
query = builder.build();
} catch (ParseException e) {
// the position might be still wrong if the parse error was at the end of the identifier
throw new ParseException(e.getMessage().replaceAll(queryData.identifier, ""));
}
SuggesterQuery suggesterQuery = builder.getSuggesterQuery();
// builder can return the suggester query if it was simple query, we ignore it in that case
if (query.equals(suggesterQuery)) {
query = null;
}
return new SuggesterData(suggesterQuery, projectList, query, builder.getQueryTextWithPlaceholder(), builder.getIdentifier());
}
Aggregations