Default Sort Order for All Fields Full-Text Query Search

Hello, I’m using the PHP SDK and just curious about the default sort order used when a general query is sent to match all fields with full-text. Without a field specified, I’m unsure what the default sort order is. I have a feeling it might be either by Entry ID or else by created or updated date?

I’m using code like this:

$query = new \Contentful\Delivery\Query();
$query->where(‘query’, $cleanedSearchTerm)->setContentType(‘basicPage’)->setSkip(0)->setLimit(25);

This code works just fine, but I’d like to better understand the order in which they are returned. Since I’m using the setSkip() and setLimit() I can’t really process a sort order once the data is returned because it would mess up the paging.

Ideally, there would be a “relevance” ordering, but I somehow doubt that is in place here.

Thanks!

I now have more content pages created and ran tests.

The default sorting for a generic “query” search is by most recently updated datetime.

Are there any options to do something that would appear to be more “relevance” based? From an end-user perspective, when they search my site, they’d want the most relevant pages at the top…they don’t care how recently I updated the content.

I’d think the number of occurrences of a search term would be sufficient and better than default. A level better would be setting a “weight” for each field.

For returning results based on relevance, I would recommend using the full-text search capabilities of the Content Delivery API, or perhaps even tagging/categorization of some kind. For even more fine-grained control over search results I would also recommend a considering a search provider, such as Algolia or Elasticsearch :+1:

Thanks for the response, Eric! I think I am using the full-text search… I’m using the generic “query” instead of a field name. Am I doing something wrong? It still returns sorted by last modified date. Is there a special “order” value to send in for relevance or number of times the query term(s) appear in a full-text search?

A search provider is certainly somewhere I might land, but I’m still starting out so likely keep it simple for now.

Sorry for the delay, Brandon! I did some additional digging, and unfortunately I was mistaken. Full-text search will definitely return relevant content; however, it will always be sorted by updated date (or any other sys or field you specify). To return an ordering based on relevance, you would have to leverage a 3rd party search provider – sorry for the confusion :sweat_smile:

Thanks again, Eric!

I think for now, I’ll build a shadow DB table that can serve as cache and allow a more customizable search to be ran on that data. Third-party search provider is probably the end solution, but for now this will probably keep me going.