Skip to main content

How to make React calls on a Drupal 9 backend site using the search functionality

Tools

Drupal 9.4
React  

 

The sample sent through from the front-end is as follows:

https://localhost/search?keyword=&sort=changed&type=%20Commissioner

However, to run requests, the keyword requires a string.  Such as searching the word 'committee'.

https://localhost:8006/search?keyword=committee

If no keyword is entered, the response will be empty.

No results found for "".

How to search for multiple words?  The keywords need to be separated by %20.  Such as committee%20people

https:/localhost:8006/search?keyword=committee%20people

Keeping the keywords 'committee' and 'people', let's apply them to sort and topic filtering.

 

Sort criteria

By default, the sort is ordered by relevance.  To change this from relevance to most recent use &sort=changed

https://localhost:8006/search?keyword=committee%20people&sort=changed

To change back to relevance use &sort=search_api_relevance

https:/localhost:8006/search?keyword=committee%20people&sort=search_api_relevance

Or you can drop the &sort for the same impact

https:/localhost:8006/search?keyword=committee%20people

 

Filter by topic

By default, all topics are shown.  To truncate the response to a set topic use &type={topic}.  Using the example topic of employment, the URL will be:

https:/localhost:8006/search?keyword=committee%20people&type=%20Employment

What about applying topics with multiple words?  As per earlier, separate the words with %20.  For example, &type=Aboriginal%20and%20Torres%20Strait%20Islander

https://localhost:8006/search?keyword=committee%20people&sort=search_api_relevance&type=Aboriginal%20and%20Torres%20Strait%20Islander

 

Related articles

Andrew Fletcher04 Apr 2025
Managing .gitignore changes
When working with Git, the .gitignore file plays a critical role in controlling which files and folders are tracked by version control. Yet, many developers are unsure when changes to .gitignore take effect and how to manage files that are already being tracked. This uncertainty can lead to...
Andrew Fletcher26 Mar 2025
How to fix the ‘Undefined function t’ error in Drupal 10 or 11 code
Upgrading to Drupal 10.4+ you might have noticed a warning in their code editor stating “Undefined function ‘t’”. While Drupal’s `t()` function remains valid in procedural code, some language analysis tools — such as Intelephense — do not automatically recognise Drupal’s global functions. This...
Andrew Fletcher17 Mar 2025
Upgrading to PHP 8.4 challenges with Drupal contrib modules
The upgrade from PHP 8.3.14 to PHP 8.4.4 presents challenges for Drupal 10.4 websites, particularly when dealing with contributed modules. While Drupal core operates seamlessly, various contrib modules have not yet been updated to accommodate changes introduced in PHP 8.4.x. This has resulted in...