Static Search

Let’s first apply search on static fields, and then we will make the search fields dynamic.

Let’s add the view, serializer, and URL pattern.

With this, we should be able to get all the questions. The search functionality isn’t added yet.

Try sending a pattern, say Samsung , as a search query parameter. search query parameter doesn’t have any effect on the returned response. Questions without the pattern Samsung are also returned in the response.

Let’s add search functionality to the view.

When we send a pattern in a GET query parameter, we want the term to be matched against the question_text column. We need to add search_fields and filter_backends to achieve this.

Let’s make the request again. We’ll only get questions that have Samsung in their question_text .

This question is authored by charles .

Let’s send charles as a search pattern in a GET request and see if we get the same response.

We did not get the expected question in response because we haven’t configured our view to match the pattern against the author column.

We can achieve that by adding author to search_fields .