How to implement snippets, an enhancement to the display of search results
To make it easier for users to read search results at a glance, add snippet functionality. When snippets are enabled, a brief portion of the document text is shown along with each search result.
Why Use Snippets?
Snippets can significantly increase the speed with which users can go from search to action, often providing enough information that the user does not even have to click on the search result link. For example, a list of results for local veterinarians might come with snippets that show each vet's phone number and address, making it easier and faster for the pet owner to quickly place a call to the nearest clinic.
Snippets can also help the user understand why a particular search is not returning the expected results. With this information, the user can refine the query.
Snippets are, in fact, so useful and so common that users probably take their presence for granted, and it is difficult to think of a reason for not using them.
How It Works
Snippets are selected by the Searchify server based on the search terms and snippet fields in the query.
- Query: specify one or more document fields from which you want to pull snippets. It's fairly typical to use the text field. If you have defined custom document fields, you can use them as well.
- Server: The Searchify server selects a portion of text to return as a snippet from each document field specified in the "snippet fields" clause of the query. The server selects the portion that contains as many as possible of the search terms from the query. For example, if the query is looking for the terms "vet" and "cat," a snippet that contians both those terms will be preferred over one that contains multiple instances of only one of the terms. The server returns up to 20 words of snippet text with the search terms highlighted.
Quick Start: Copy & Paste
Tweak the following code for your needs, and you're ready to go
Before you start
Set Snippet Fields in Query
The following code shows how to request snippets.
- Searching in the Searchify API reference