The application is pretty simple, but extremely flexible in terms of searching data.
Behind the scenes, the user inputted query is converted to a query_string query that is sent to Elastic. The query_string query provides native support for a number of search syntax options, but we're mostly interested in wildcards, boolean operators, phrase matching and boosting.
The user inputted string is proccessed in the following way:
- Exact phrases to look for are marked with quotes ("an example phrase").
- Each word/phrase that isn't marked in any way (example) will be present in the result set's ingredients.
- Each word/phrase that is marked with a minus (-example) will not be present in the result set's ingredients.
- Each word/phrase can be boosted to become more relevant (score higher) in the search results.
So, if we want to look for recipes containing garlic, tomatoes, chopped onions and not containing eggs and red-pepper flakes, we'll have to input the query string:
garlic^2 tomatoes -egg "chopped onions" -"red-pepper flakes"* // Order doesn't matter
As you can see, we've boosted the garlic. This means that recipes where garlic appears more frequently will score higher.
The asterisk symbol following the egg is called a wildcard query. It means that it's going to look for words that start with egg and continue with anything else, no matter the length (for example, egg* is going to match eggs, eggplant, eggbeater, etc.), very similar to SQL's like.
You can substitute the asterisk with a "?" sign, which will indicate that Elastic should look for just a single missing letter.
How to run
In order to run the application, you must install and run elastic then execute the following steps:
- Clone the repository.
- Open the project in Visual Studio and restore packages (Ctrl + Shift + K, Ctrl + Shift + R).
- Run the application (Ctrl + F5).
In order to make use of the search functionality, you must have some recipes indexed in your elastic cluster.
First, make sure that the cluster url in
appsettings.json is correctly configured then:
- Download the openrecipes dump json file.
- Extract the json file in
project-root\src\ElasticsearchRecipes\Data(create the Data folder if it doesn't exist).
- While the application is running, make a get request to
- In a few minutes you should see a json response confirming that the indexation was valid.
Everything should be set-up and you are free to play around.