Insights

Creating Sub-Items Using Coveo Web Source

How To Create Sub-Items Using Coveo's Web Source

It's not a well advertised feature of the Coveo Web Source, but you can generate what's called Sub-Items from even a single page of data. And you can do so, very, easily.

Typically you would use Sub-Items when an "item" has no specific URL that can be browsed to. The other being, when you are not looking to link the search result to a page found at the source you're on, or for some other purposes.

Configure A Web Source

The first thing you'll need is a Web Source and an appropriate web page. For the purposes of our example, I'm using a page on https://boardgamegeek.com/hotness. What makes for a valid sub-item source? Well, that depends. Ultimately you're looking for a list of some sorts. For example:

  • Community Forums
  • Blog Post Comments
  • Product Data Tables or Lists, etc.

The list can be in in any HTML structure as long as it's a repeating structure and it's something you can programmatically capture via XPATH or CSS selectors.

Configure Sub-Item Structure

Within the Web Source created above, you can go to Web Scraping on the right side and within the JSON configuration update it in a similar fashion.

[{
    "for": {
      "urls": [".*"]
    },
    "exclude": [{}],
    "metadata": {},
    "subItems": {
      "BGGSubItem": { // Give it a name
        "type": "CSS",
        "path": ".numbered-game-list__item"  // The CSS selector of the element containing a single item
      }
    }
  }, {
    "for": {
      "types": ["BGGSubItem"] // Loop through the items in the list
    },
    "exclude": [{}],
    "metadata": {
      "title": {
        "type": "CSS",
        "path": ".stretched-link::text" // The CSS selector of the text we want to use as the title
      }
    }
  }]

Under subItems we first give the item to be indexed a name, in our case BGGSubItem.

Next we use a CSS selector .numbered-game-list__item to identify the element containing the item.

Lastly, within the "for" loop map the data we want to use to appropriate metadata fields in Coveo.

Now you could go much further, assigning other values to other appropriate metadata items if so desired but for this example, we're keeping it simple. You'll notice that even doing this bare-minimum Coveo has auto detected the appropriate description text for each item.

Coveo web scraping sub-items

Use Extensions To Re-Map The Clickuri Value

Or any other metadata value for that matter. Something you may have noticed in the above image is that the URI contains the string SubItem:##.

If you're not planning on linking a search result to another page, this may be something you can ignore, however, if you are, then you would want to update the clickuri metadata value through use of an extension.

👋 Hey Sitecore Enthusiasts!

Sign up to our bi-weekly newsletter for a bite-sized curation of valuable insight from the Sitecore community.

What’s in it for you?

  • Stay up-to-date with the latest Sitecore news
  • New to Sitecore? Learn tips and tricks to help you navigate this powerful tool
  • Sitecore pro? Expand your skill set and discover troubleshooting tips
  • Browse open careers and opportunities
  • Get a chance to be featured in upcoming editions
  • Learn our secret handshake
  • And more!
Sitecore Snack a newsletter by Fishtank Consulting
 

Meet David Austin

Development Team Lead | Sitecore Technology MVP x 3

📷🕹️👪

David is a decorated Development Team Lead with Sitecore Technology MVP and Coveo MVP awards, as well as Sitecore CDP & Personalize Certified. He's worked in IT for 25 years; everything ranging from Developer to Business Analyst to Group Lead helping manage everything from Intranet and Internet sites to facility management and application support. David is a dedicated family man who loves to spend time with his girls. He's also an avid photographer and loves to explore new places.

Connect with David