use of com.rbmhtechnology.vind.api.query.suggestion.DescriptorSuggestionSearch in project vind by RBMHTechnology.
the class SolrSearchServer method buildSolrQuery.
protected SolrQuery buildSolrQuery(ExecutableSuggestionSearch search, DocumentFactory assets, DocumentFactory childFactory) {
final String searchContext = search.getSearchContext();
final SolrQuery query = new SolrQuery();
query.setRequestHandler("/suggester");
if (search.isStringSuggestion()) {
StringSuggestionSearch s = (StringSuggestionSearch) search;
query.setParam("suggestion.field", s.getSuggestionFields().stream().map(name -> {
if (Objects.nonNull(childFactory)) {
final FieldDescriptor<?> field = Objects.nonNull(assets.getField(name)) ? assets.getField(name) : childFactory.getField(name);
if (Objects.isNull(field)) {
log.warn("No field descriptor found for field name {} in factories: {}, {}", name, assets.getType(), childFactory.getType());
}
return getFieldname(field, UseCase.Suggest, searchContext);
} else {
if (Objects.isNull(assets.getField(name))) {
log.warn("No field descriptor found for field name {} in factory: {}", name, assets.getType());
}
return getFieldname(assets.getField(name), UseCase.Suggest, searchContext);
}
}).filter(Objects::nonNull).toArray(String[]::new));
} else {
DescriptorSuggestionSearch s = (DescriptorSuggestionSearch) search;
query.setParam("suggestion.field", s.getSuggestionFields().stream().map(descriptor -> getFieldname(descriptor, UseCase.Suggest, searchContext)).filter(Objects::nonNull).toArray(String[]::new));
}
query.setParam("q", search.getInput());
// TODO: somehow this is still needed here, it should by configuration
query.setParam("suggestion.df", SUGGESTION_DF_FIELD);
query.setParam("suggestion.limit", String.valueOf(search.getLimit()));
String parentTypeFilter = "_type_:" + assets.getType();
if (Objects.nonNull(childFactory)) {
parentTypeFilter = "(" + parentTypeFilter + " OR _type_:" + childFactory.getType() + ")";
}
query.add(CommonParams.FQ, parentTypeFilter);
// filters
if (search.hasFilter()) {
SolrUtils.Query.buildFilterString(search.getFilter(), assets, childFactory, query, searchContext, false);
new SolrChildrenSerializerVisitor(assets, childFactory, searchContext, false);
}
// suggestion deep search
if (Objects.nonNull(childFactory)) {
if (search.hasFilter()) {
// TODO clean up!
final String parentFilterQuery = "(" + String.join(" AND ", query.getFilterQueries()) + ")";
final String childrenFilterQuery = search.getFilter().accept(new SolrChildrenSerializerVisitor(assets, childFactory, searchContext, false));
final String childrenBJQ = "{!child of=\"_type_:" + assets.getType() + "\" v='" + childrenFilterQuery + "'}";
query.set(CommonParams.FQ, String.join(" ", parentFilterQuery, "OR", childrenBJQ));
}
}
return query;
}
Aggregations