use of com.erudika.para.server.search.es.ESUtils.PROPS_PREFIX in project para-search-elasticsearch by Erudika.
the class ES method findTermInListInternal.
public static <P extends ParaObject> List<P> findTermInListInternal(String appid, String type, String field, List<?> terms, Pager... pager) {
if (StringUtils.isBlank(field) || terms == null) {
return Collections.emptyList();
}
QueryVariant qb;
if (nestedMode() && field.startsWith(PROPS_PREFIX)) {
QueryVariant bfb = null;
BoolQuery.Builder fb = QueryBuilders.bool();
for (Object term : terms) {
bfb = keyValueBoolQuery(field, String.valueOf(term));
fb.should(bfb._toQuery());
}
qb = (QueryVariant) nestedPropsQuery(terms.size() > 1 ? fb.build() : bfb).build();
} else {
List<FieldValue> values = terms.stream().filter(Objects::nonNull).map(v -> FieldValue.of(fv -> fv.stringValue(v.toString()))).collect(Collectors.toList());
qb = QueryBuilders.terms().field(field).terms(t -> t.value(values)).build();
}
return searchQuery(appid, type, qb, pager);
}
use of com.erudika.para.server.search.es.ESUtils.PROPS_PREFIX in project para-search-elasticsearch by Erudika.
the class ES method findSimilarInternal.
public static <P extends ParaObject> List<P> findSimilarInternal(String appid, String type, String filterKey, String[] fields, String liketext, Pager... pager) {
if (StringUtils.isBlank(liketext)) {
return Collections.emptyList();
}
QueryVariant qb;
String matchPercent = "70%";
if (fields == null || fields.length == 0) {
qb = QueryBuilders.moreLikeThis().like(l -> l.text(liketext)).minDocFreq(1).minTermFreq(1).minimumShouldMatch(matchPercent).build();
} else {
boolean containsNestedProps = Arrays.stream(fields).anyMatch((f) -> StringUtils.startsWith(f, PROPS_PREFIX));
if (nestedMode() && containsNestedProps) {
BoolQuery.Builder bqb = QueryBuilders.bool();
for (String field : fields) {
QueryVariant kQuery = QueryBuilders.match().field(PROPS_PREFIX + "k").query(v -> v.stringValue(getNestedKey(field))).build();
QueryVariant vQuery = QueryBuilders.moreLikeThis().fields(PROPS_PREFIX + "v").like(Like.of(l -> l.text(liketext))).minDocFreq(1).minTermFreq(1).minimumShouldMatch(matchPercent).build();
QueryVariant nested = (QueryVariant) nestedPropsQuery(QueryBuilders.bool().must(kQuery._toQuery(), vQuery._toQuery()).build()).build();
bqb.should(nested._toQuery());
}
qb = bqb.build();
} else {
qb = QueryBuilders.moreLikeThis().fields(Arrays.asList(fields)).like(l -> l.text(liketext)).minDocFreq(1).minTermFreq(1).minimumShouldMatch(matchPercent).build();
}
}
if (!StringUtils.isBlank(filterKey)) {
qb = QueryBuilders.bool().mustNot(QueryBuilders.term().field(Config._ID).value(v -> v.stringValue(filterKey)).build()._toQuery()).filter(qb._toQuery()).build();
}
return searchQuery(appid, searchQueryRaw(appid, type, qb, pager));
}
Aggregations