In this getting started guide, you will add search functionality to the Address Book app that you build in the Macrometa Quickstart.
Step 1. Create a View
A search view is an inverted index that contains the search configuration and all document attributes across one or many collections.
- On the side menu, click Search Views.
- Click New View.
- In Name, enter
- Click the plus under Mapping Definition.
- Select the
addressescollection from the COLLECTION list.
fieldand select text_en in the ANALYZER list.
- Follow steps 5 and 6 two more times, but add
firstNamein the second Mapping Definition and
- Click Create.
Macrometa distributes this view index to every location in the global fabrics. If you're curious about the locations, click Dashboard to see the default GeoFabric locations.
Our view is now accessible worldwide, and your three address collection key values are indexed and ready to query!
Step 2. Query your View
On the side menu, click Query Workers.
The code block below is a search query that will allow you to pass in a query parameter to search you index. Copy and paste it in the code editor on line 1.
FOR contact IN addresses_view
BOOST(STARTS_WITH(contact.firstName, @searchTerm), 3) OR
BOOST(STARTS_WITH(contact.lastName, @searchTerm), 2) OR
BOOST(STARTS_WITH(contact.email, @searchTerm), 1),
SORT BM25(contact) DESC
RETURN UNSET(contact, ["_id", "_rev"])
Add the word
nemoto the searchTerm value to the right of the query editor window.
Click Run Query. You will see your results show up below the Run Query button.
(Optional) Click Query Info in the Query Result to see what the query did and how long each step took. Pretty cool if you're into performance metrics.
Step 3. Save the Query as an API Endpoint
Macrometa allows you to save a query as a Query Worker.
- Click Save Query.
- Name the query getContactBySearchTerm and then click Save. This saves the query so you can use it again.
- Click Run Query.
- Click API Endpoint.
Macrometa displays a cURL command that you can use to access this endpoint from anywhere in the world in under 50ms.
This query requires a value to be passed with each request, so you must enter one in the bind parameters or else the query will fail with an error.
You have created your first view and made it a RESTful endpoint with a query worker. We made a front-end for you to take your new backend for a spin.