2

I'm using a non-edge GraphQL endpoint to leverage keyword search and faceting in my content search queries. This means that I'm using the Sitecore.Services.GraphQL.Content.Queries.SearchQuery class instead of the Sitecore.Services.GraphQL.EdgeSchema.Queries.SearchQuery that comes with the Edge schema.

My query looks like this:

query(  $language: String = "en"
        $keyword: String!
        $first: Int = 10
        $after: String
     ) {
  search(
      rootItem: "/sitecore/content/Client/MainSite/Home",
      keyword: $keyword,
      first: $first,
      after: $after,
      fieldsEqual:[
        {name:"_haslayout", value:"true"},
        {name:"_latestversion", value:"true"},
        {name:"_language", value: $language}
      ],
  ) {
    results {
      totalCount
      pageInfo {
        hasNextPage
        hasPreviousPage
      }
      items {
        score
        item {
          displayName
          template {
              name
          }
        }
      }
    }
  }
}

I get results back, but the relevancy is unclear. The biggest thing that I notice is that the score field is the same for every result item.

{
    "data": {
        "search": {
            "results": {
                "totalCount": 3,
                "pageInfo": {
                    "hasNextPage": false,
                    "hasPreviousPage": false
                },
                "items": [
                    {
                        "score": 4.8768038749694824,
                        "item": {
                            "displayName": "Health benefits of coffee",
                            "template": {
                                "name": "Article"
                            }
                        }
                    },
                    {
                        "score": 4.8768038749694824,
                        "item": {
                            "displayName": "Dr. Pepper",
                            "template": {
                                "name": "Person"
                            }
                        }
                    },
                    {
                        "score": 4.8768038749694824,
                        "item": {
                            "displayName": "Nespresso",
                            "template": {
                                "name": "Product"
                            }
                        }
                    }
                ]
            }
        }
    }
}

Has anyone run into this and figured out how to correct it?

2
  • 2
    I think this is more related to the index query itself and not the grahpql. If you check the (search) logs you will see actual query that is performed when you do this query. You can test that query towards your solr and that should give you the same results. That should be the starting point for your investigation.
    – Gatogordo
    Jul 19, 2022 at 7:47
  • This is a good suggestion. I did reproduce the Solr query and got different results. The key difference is that the score should never be the same across all result documents. Jul 19, 2022 at 13:45

1 Answer 1

1

Conclusion

After looping in Sitecore support and comparing the GraphQL and Solr responses. The issue appears to be rooted in the Solr query parser's ability to rank results based on the _content computed field.

Under the covers, when you populate the keyword argument for the Sitecore.Services.GraphQL.Content.Queries.SearchQuery class is using the LINQ Contains() operator which adds a WHERE clause to the query parameter passed to Solr like this:

q=_content:"*caffeine*"

Because the _content field is a computed field that aggregates content from several different text and media fields, the default query parser is unable to appropriately rank the results.

In my case, this is a deal-breaker for using GraphQL for keyword and faceted search.

Best Alternative (although not supported by the Content Search API)

The DisMax query parser is designed to process simple phrases (without complex syntax) entered by users and to search for individual terms across several fields using different weighting (boosts) based on the significance of each field. Additional options enable users to influence the score based on rules specific to each use case (independent of user input).

In general, the DisMax query parser’s interface is more like that of Google than the interface of the 'standard' Solr request handler. This similarity makes DisMax the appropriate query parser for many consumer applications. It accepts a simple syntax, and it rarely produces error messages.

https://solr.apache.org/guide/8_8/the-dismax-query-parser.html#the-dismax-query-parser

4
  • You can accept your own answer. Which would be quite nice since it contains very useful information.
    – Fabian
    Aug 10, 2022 at 12:44
  • Are there any arguments against using the SOLR API directly?
    – Fabian
    Aug 10, 2022 at 12:48
  • @Fabian there is a significant need for an eDismax GraphQL query in the Sitecore community. This would provide a necessary abstraction layer between the client and Solr. Personally I try to avoid executing REST requests directly against Solr from the client / browser for security reasons. Aug 11, 2022 at 13:55
  • Thank you for the clarification. Once you got content that needs to be secured direct access should not be given. Is there some kind of feature request which can be supported?
    – Fabian
    Aug 11, 2022 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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