SRP API - "Contains" Search or Full Text UGC Filtering?

Avatar

Avatar

Gdubz-57m2mu

Avatar

Gdubz-57m2mu

Gdubz-57m2mu

28-11-2016

Is it possible to filter strings by "contains" or maybe a full text search for UGC?

I've tried a ValueConstraint<String>[1] but looks like I can only perform a "begins with" search based on the available ComparisonTypes[2]. Even still, this doesn't seem to work...

final UgcFilter filter = new UgcFilter(); // ... final String titleFilterParam = request.getParameter("title"); ConstraintGroup optionalFilters = new ConstraintGroup(Operator.Or); Constraint titleFilter = new ValueConstraint<String>("postTitle", titleFilterParam, ComparisonType.BeginsWith); optionalFilters.addConstraint(titleFilter); filter.and(optionalFilters);

So then I tried a FullTextConstraint[3] on a specific property and that doesn't seem to work either.

final UgcFilter filter = new UgcFilter(); // ... final String titleFilterParam = request.getParameter("title"); ConstraintGroup optionalFilters = new ConstraintGroup(Operator.Or); optionalFilters.addConstraint(new FullTextConstraint(titleFilterParam, "postTitle"); // not sure which wildcard is valid (if any), no documentation on this optionalFilters.addConstraint(new FullTextConstraint("*" + titleFilterParam + "*", "postTitle"); optionalFilters.addConstraint(new FullTextConstraint("%" + titleFilterParam + "%", "postTitle"); filter.and(optionalFilters);

I've looked at the only filtering examples I've seen from Adobe on the github here[4] but that only shows an example of a ValueConstraint<Boolean> and a PathConstraint[5]. String value comparison using ValueConstraint<String> also seems to have a hard time with capitalization and spaces, so I've had to lowercase and replace all spaces with hyphens for string comparison, for now. Is there a better way to do this?!

I guess I could always just filter in my code after the fact, but figured we should get the UgcFilter correct the first time. This is extremely frustrating though, considering I can't get a printout of what the final UgcFilter looks like before querying Solr (like what the final XPath/JCR-SQL2/etc query string is).

[1] https://docs.adobe.com/docs/en/aem/6-2/develop/ref/javadoc/com/adobe/cq/social/ugc/api/ValueConstrai...
[2] https://docs.adobe.com/docs/en/aem/6-2/develop/ref/javadoc/com/adobe/cq/social/ugc/api/ComparisonTyp...
[3] https://docs.adobe.com/docs/en/aem/6-2/develop/ref/javadoc/com/adobe/cq/social/ugc/api/FullTextConst...
[4] https://github.com/Adobe-Marketing-Cloud/aem-communities-todomvc-sample/blob/master/bundles/aem-comm...
[5] https://docs.adobe.com/docs/en/aem/6-2/develop/ref/javadoc/com/adobe/cq/social/ugc/api/PathConstrain...

View Entire Topic

Avatar

Avatar

snbaem

Avatar

snbaem

snbaem

19-04-2018

It looks like we still have an issue with the "contains" text search.

The FullTextConstraint API does work partially with the wildcard, but if the search text contains a space it doesn't return any results.

For eg:- If we have an entry as "Testing rich text contents", we can use FullTextConstraint with the wildcard and if the user enters "rich" or "text" it returns us the matching record which is "Testing rich text contents", but if we enter the search term as "rich text" there are no records returned (The expected result is "Testing rich text contents").

We have tried the solution that was provided here and additionally we have tried the following as well (as suggested here),

final ConstraintGroup optionalGroup = new ConstraintGroup();

if (StringUtils.isNotEmpty(searchText))

{

optionalGroup.or(new FullTextConstraint("/.*" + searchText + ".*/i", PropertyConstants.TITLE_T));

}

requiredGroup.and(optionalGroup);

Not sure if we still have a bug that is prohibiting the API to search for text's with a space or if there is a workaround to implement wildcard searches that can accept space?

Can anyone from the community group help and provide a solution for this issue?