Why using structured results?

- Google calls them “Knowledge Graph Cards”,
- Bing calls them “Visually Rich Snippets”,
- DuckDuckGo and Baidu all have their own flavors as well.
Uses for structured results
You’ll want to use structured results whenever there is a singular piece of information you want to stand out from the rest for a given query. Here are a few examples:- Movie titles on an entertainment website
- User details and avatar on a customer relationship management (CRM) system
- Sponsored brands on an ecommerce search (see example and code on GitHub).
An example
First, take a look at the ecommerce example mentioned in the preceding section. You can view the code and follow along on GitHub. Imagine a scenario where certain brands within your ecommerce site have requested that their brand will be displayed if it happens to match a user’s query. In your search, if you determine that someone is searching for a particular brand name, you can embed a section displaying the brand and its name within the main search interface.How will the data look?
One index will be the main index to host traditional results - in your case, tech products - regardless of a match on the brand. Another index will be used to store your brands as records like so:JSON
Tweaking the relevance
Now that you added a new index for structured results to use in conjunction with your main index, outline what you’d like to emphasize in your structured results:- Only display a single result that matches a user’s search
- Continue to handle typos, but be more stringent
- Ensure that you have all words matching in order (so “The Bad News” and “The Bad News Bears” would match but “Bears Bad News” would not)

JavaScript

JavaScript
Displaying the data
Federated search makes it easy to perform a single query against several datasets. You can use it with your structured brand result:Vue
ais-index
widget to nest multiple indices that share the same uiState
(or “search state”).
When a user searches in the app, it searches in both the main and the structured indices.
You can use the ais-configure
widget to:
- Stay on the first page (
0
sincepage
is zero-based) because the main index can be paginated, and the structured index would then “inherit” from its pagination state. - Set
hitsPerPage
to1
because you only show the first result. - Set
getRankingInfo
totrue
so that Algolia returns metadata about the hit’s ranking.
ais-hits
connector and do a conditional check:
Vue
exact word matches - 1
There’s no requirement as to when to display your content, this part is up to you.
Another constraint you may impose on the rendering of the structured result could be to check that the count of exact word matches is equal to the number of words in the value of the attribute being queried. For example, you may only want to show a brand when all words of that brand have been typed. Check the getRankingInfo
documentation to learn about other useful metrics you can access in the results.
Another example, a different use case
Now imagine you’re iterating on an entertainment website that displays structured results on movies: if you can determine that someone is searching for a specific movie, you will embed a section displaying the movie details within the main search interface. That is, you’d like to communicate to users that there might be a salient piece of content worth showcasing.How will the data look?
Consider how you should structure your data. First, you need a main index, as with the ecommerce example. This is where people will always see traditional results even if there’s no structured data match. Think about a major search engine when you search a new movie: you might get structured results with the cast, showtimes, and video clips at the same time. In Algolia, that would require three extra indices—one for each result type. This example is a bit simpler, as it only has a single data type to show structured results: movies. Yet, you can imagine a circumstance where you would match on actors, directors, etc. Here’s how a sample movie record could look like:JSON