SRP API - "Contains" Search or Full Text UGC Filtering? | Community
Skip to main content
Gdubz-57m2mu
New Participant
November 28, 2016
Solved

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

  • November 28, 2016
  • 11 replies
  • 4703 views

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/ValueConstraint.html
[2] https://docs.adobe.com/docs/en/aem/6-2/develop/ref/javadoc/com/adobe/cq/social/ugc/api/ComparisonType.html
[3] https://docs.adobe.com/docs/en/aem/6-2/develop/ref/javadoc/com/adobe/cq/social/ugc/api/FullTextConstraint.html
[4] https://github.com/Adobe-Marketing-Cloud/aem-communities-todomvc-sample/blob/master/bundles/aem-communities-todomvc/src/main/java/com/adobe/aem/social/todomvc/impl/TodoListImpl.java#L79
[5] https://docs.adobe.com/docs/en/aem/6-2/develop/ref/javadoc/com/adobe/cq/social/ugc/api/PathConstraint.html

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Gdubz-57m2mu

Thank you sooooo much for sticking with me on this one, Calvin! You're incredible.

Got it working with the following code:

final UgcFilter filter = new UgcFilter(); // ... required filters ... final ConstraintGroup optionalGroup = new ConstraintGroup(Operator.And); // ... other optional filters ... // Title "Contains" Filter final String titleFilterParam = request.getParameter("title"); if (StringUtils.isNotEmpty(titleFilterParam)) { optionalGroup.addConstraint(new FullTextConstraint("*" + titleFilterParam + "*", "postTitle_s"); } filter.and(optionalGroup);

Again, can't thank you enough!

11 replies

New Participant
November 29, 2016

You can get the search queries, SQL2 for JSRP or Lucene for MSRP, if you enable DEBUG logging for com.adobe.cq.social.ugc.impl.LuceneUgcSearch. With the debug queries, you can try them directly in CRX/DE for JSRP or the Solr Admin console for MSRP.