Search filters Integration
Lesson 8 of 10 in Coddy's Social media Search Project - Python JSON Fundamentals course.
Your task for the day is to integrate the search UI and the backend.
User can type their search key along with several filters in the UI. This is sent to the backend system (your python code) in a string format.
Here's a sample format:
"key=David&type=user&city=Paris"The above string is sent to the backend system when user types in "David" in the search input. Then selects the following filters - entity as user and city as Paris.
This format is a string with key=value pairs separated by & character. Keys and values could be anything.
For better understanding, let's try another possible example:
"key=Alex&gender=F&job=Engineer"This search string indicates that the user searched for Alex in the input and then selected the filters: Female for gender and job as Engineer.
Your company is implementing several more filters.
Because of that, you need to convert the query string you receive into a python dictionary object for further processing. Query string can contains any possible key/value.
Challenge
EasyWrite a function get_search_filters that gets,
filter_str- string - this will be key-value pairs in the format: key1=value1&key2=value2&key3=value3
And returns a dictionary object in the below format:
{"key1": "value1", "key2": "value2", "key3": "value3"}
Note 1: filter_str can contain any number of key-value pairs. The returned dictionary object needs to contain all of those key-value pairs.
Note 2: filter_str could be an empty string
Example:
Input - "key=David&type=user&city=Paris"
Expected Output - {'key': 'David', 'type': 'user', 'city': 'Paris'}
Explanation - Each of the key-value paris identified in the filter_str input is added as key-value pairs in the dictionary output object.
Try it yourself
def get_search_filters(filter_str):
# write code here