1

The following GraphQL query returns items based on the Page template:

  search(keyword: "Dream",
    first: 10, 
    language: "en",
    fieldsEqual: [{name:"_templatename", value:"Page" }]
  ) {
    results {
      items {
        name
        id
        language
        item {
          url
        }
      }
    }
  }
}

ATM, Page is the only page template in the solution so the query works fine. There is a need to introduce new (numerous) page types like Product Page, FAQ, Organization inheriting Page (mainly for the content editor usability to assign proper insert options).

How to extend the query to cover all the pages inheriting Page template?

0
1

Instead of targeting the _templatename field you should target the multi-valued _templates field which contains the inheritance tree for an item. Since this will get translated into a Solr query, despite the fact that we're using the "fieldsEqual" argument the field only needs to contain the value, which is perfect for our inheritance filtering use case.

Here's what the changed argument should look like (be sure to change the ID):

   fieldsEqual: [{name:"_templates", value:"e6fd0c645a27449caafece6f377b3e3e" }]

You'll notice that the value needs to be template ID we're looking for, not the name of it. You also need to make sure the ID is normalized to what gets indexed (no brackets, lower case alpha, and no dashes).

If you need to dynamically convert your templates to useable ID's at query time, you may find this method useful: Sitecore.ContentSearch.Utilities.IdHelper.NormalizeGuid

0

Currently, there is no OR in the search, you can do a search for each page type, or first do a facetOn: _templatename than you know how many items there are for each templateName

But to keep it simple add a CheckBox Field with for example name IncludeInSearch default value 1 to all Page template that can include in the search. and use

fieldsEqual:[{name:"IncludeInSearch", value:"1" } ]

and re-index your index.

As a side effect editor have no the option to hide also pages from the search.

1
  • I think it's inaccurate to say there's no "OR" in search. There not might be a boolean OR on the entire field/value collection, but that's not what's being asked. It's enough that solr (or azure, or other document datastores) will treat "equals" as "does this field have this value in any of its values" Targeting the IncludeInSearch field does not answer the question on filtering items based on template inheritance and can be leveraged regardless of the Page template being used. Jul 16 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.