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