Gravatar for

Question by Alok Gupta, Jul 18, 2016 1:34 PM

excluding orphans using folding feature


We are using folding feature to display questions and answers. Questions are tagged with certain topics and the topics are displayed as a facet on the search results page. One of the requirement is to exclude certain tags. We excluded all the questions that were tagged with excluded tags by creating a custom field "crawlingpage=false (using custom script) and then applied the filter "NOT crawlingpage=false" during the query execution. Everything is good except the replies to these excluded questions are displaying on the search result pages. Is there a way we can ignore all the orphan replies from UI?


1 Reply
Gravatar for

Answer by Daniel Lavoie, Jul 18, 2016 2:25 PM

Hi, You can solve your issue using nested queries.

Assuming your folding field is named @questionid, you can change your filter to this:

NOT [[@questionid] @crawlingpage=false]

This basically means, return all the @questionid values for which @crawlingpage is false, and then don't return any document having this value, question or answer.

This will require your folding field to be a facet, it is a requirement for nested queries.

Gravatar for

Comment by Alok Gupta, Jul 19, 2016 12:02 AM

Thanks Daniel. I tested this out and it is working great. I've couple of related questions -

  1. Can I apply this nested query when requesting a search token?
  2. Is there any documentation available on Nested Queries?


Gravatar for

Comment by Daniel Lavoie, Jul 19, 2016 8:04 AM

Hi, Happy that the solution works for you.

I don't know the answer to 1. As for documentation, I don't find any, I will check with our documentation team to make sure a section is added. In the meantime, here is what I documented internally when I developed the feature:


The Nested Query feature makes it possible to perform a query on a subset of documents and use a predicate on another set of documents, just like a sub-select in SQL.


The syntax is pretty straightforward: OutExpression @Outfield=[[@Infield] InExpression]

In the case where @Outfield = @Infield, this syntax can be used: OutExpression [[@field] InExpression]

The SQL equivalent query would be: SELECT * FROM Index WHERE Outfield IN (SELECT Infield FROM Index WHERE InExpression)

Recursive nested queries are now also supported. For example: filter1 [[@id1] filter2 [[@id2] filter3]]

Examples: In this section, we will provide a few examples of use.

type:players [[@playerid] @hr > 50 @rbi > 100 @avg > 0.3 type:batting]

walmart or @parentid=[[@topparentid] walmart @sysisattachment]

filetype:sfaccount [[@syssfaccountid] filetype:opportunity syssfowner:fpare @syssfamount > 50000 Q3-2012]

Requirements: In order for nested queries to work, you need to:

  • set your fields (@InnerField and, if applicable, @OuterField) as a facet for the string type,

  • or as a fast numerical field for the numerical types.

  • It's done automatically if you put your fields in in the section of the config.

Ask a question