As part of a longer series, we have prepared an API to retrieve thumbnails using playwright. In this article, we will apply this API to Sitecore Search.
![](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F4wLrw1pMKjSIqT8nPMmnpU%2Fef72e290d25a26806381a5f73eec37c1%2Fnick-fewings-kwhwJsxiH_4-unsplash.jpg&w=3840&q=75)
Creating New Sources
In this article, we will implement a mechanism to display thumbnails as search results for XM Cloud documents in English at https://doc.sitecore.com/xmc.
In creating the sources, Document Extractors were set up as follows.
- Select JS as Extractor Type
- URLs to Match uses Regular Expression to create a . *\/xmc\/. * Specify .
- For Tagger, set the following JavaScript code
- In this case, the server of the API that creates the thumbnails is specified by image_url
- The URL of the sample site on this page is a dummy
function extract(request, response) {
$ = response.body;
let url = request.url;
return [{
'title': $('h1').text(),
'subtitle': $('meta[name="description"]').attr('content') || $('section[data-component-name="Hero Banner"] div[class*="side-content"]>div>p, header div.lead p').text(),
'description': $('meta[name="description"]').attr('content') || $('meta[property="og:description"]').attr('content') || $('p').text(),
'name': $('meta[name="searchtitle"]').attr('content') || $('title').text(),
'image_url': "https://yoursampleserver.vercel.app/api/thumbnail?url=" + url,
'product': $('meta[name="product"]').attr('content'),
'type': 'Documentation',
'site_name': 'Sitecore Documentation',
'url': url
}];
}
The crawler now retrieves the data and specifies the API to create and display thumbnails for the images on that page.
Confirmation of operation
Since we are loading the XM Cloud documentation, we will enter XM as a keyword. First of all, you will see a screenshot of the screen as a recommendation when you enter the keyword.
![searchthumbnail01.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F46wd52w9rTL9BY2cDQ1E0Q%2F48c7b7d86b648f3d354bd6902f7c64e6%2Fsearchthumbnail01.png&w=3840&q=75)
Thumbnails are also used as images in the list of search results.
![searchthumbnail02.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F3k5kLwHk5B584Hj6EjvauU%2F57400fcdf43a86150a004cd03d15a492%2Fsearchthumbnail02.png&w=3840&q=75)
Thumbnails are also used on the search results page.
![searchthumbnail03.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F1fJnBMA7mFZuR10KxLts0K%2Ffc665e2575ab990432a60a82e411c480%2Fsearchthumbnail03.png&w=3840&q=75)
Summary
If the images to be used for a page are clearly defined in the product information, etc., this system of using images is not necessary. However, preparing images for search results for all pages is a high hurdle in terms of man-hours and cost-effectiveness, but with the thumbnail system using Playwright, images could be displayed for search results.