Search Results Page

Wondering how to create a search results page like that would function like https://user-guides.prismic.io/en/?q=search+results+page

Is it possible to query the whole document and return the snippet around the key word and highlight that word?

Hey Joe!

Which technology are you using to query the data from your repository?

If you want to build a search bar for your site you can use the Fulltext search predicate to search a document for a given term or terms. Then, by using Fetch links you can fetch a specific content field from a linked document.

This predicate will look for coincidences in these fields: Rich Text, Title, Key Text, UID, and Select fields.

If you need to create a more robust search you can use a third-party service like Algolia.

Hey, thanks for your response.

We are using node.js.

I am able to get the data via search, but was wondering if there was an example that had pulled a snippet of text out around the key word match.

I don’t fully understand this: “pulled a snippet of text out around the key word match”.
Which snippet are you referring to?

So that would be the text that was found in the search. I could probably figure this out, was just wondering if anyone had ideas or has done this before.

Basically I want to highlight the searched term in the results. In order to do that I need to return the paragraph around the searched term in the results.

You mean like the bold parts here?

I’m pretty sure there is no way, you’d have to do an additional search on the client side. Ensuring the search algorithms agree would be the main challenge I think. @paulina.gavilan can you shed any light on how it works on the Prismic end?

That is exactly what I would like to do.

We do have an example in Node of something similar!

See Live Demo

This Sample Blog shows a homepage with a preview of the posts, it shows a title and the date publish date. Take a look at the code to see how we call some specific fields for each post preview inside the home query.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.