.Related finds no pages

I have a website (https://www.databasesandlife.com/) built with Hugo. It has about 290 blog posts in about 30 different categories.

I am trying to implement related content. But the .Related function doesn’t find any related pages. (Always returns an empty list.)

The documentation for Related states

To list up to 5 related pages is as simple as including something similar to this partial in your single page template:

In the layouts/_default/single.html template I have added the following (I am trying to do some debugging to see what the .Related function returns)

<br>this page = {{ . }}
<br>RegularPages = {{ .Site.RegularPages }}
<br>Related = {{ .Site.RegularPages.Related . }}
<h1>END RELATED</h1>

On every blog article I see output like:

this page = Page(/playing-a-cd-on-a-computer.mmark)
RegularPages = Pages(253) 
Related = Pages(0)

According to the docs there is nothing mandatory to configure. (But I tried pasting the default config into the config.toml file anyway, and setting the threshold to 2 (out of 100) to try and match more pages.)

I am using Hugo 0.46.

What am I doing wrong? Or how can I go about debugging this for myself? I’ve sat in front of this for half an hour now, trying all different combinations I can think of but it doesn’t change anything.

Thanks in advance!

OK based on another post on this forum, if I put

keywords: [blog]

in the front-matter of all blog posts, it finds related posts.

Perhaps the doc could be updated to describe what keywords means? I don’t see how it’s distinct from the categories (or other taxonomies) or the sections.

Is it something that is required only for the related feature or does it have some other effect as well?

You are right about the documentation part. We wil fix that.

The default config builds indexes from date and keywords because these are reserved front matter fields in Hugo, so many people will have values in these. Many themes use the keywords list to create the keywords meta tag, and it felt natural to use that as a “default related” index.

But as you have noted, no default config fits everyone.

1 Like

According to https://github.com/gohugoio/hugo/blob/master/related/inverted_index.go .Related works off a few different factors:

Keywrods, and date, as mentioned by @bep, but also ‘tags’. You also have to configure this in hugo.

Config is the top level configuration element used to configure how to retrieve
related content in Hugo.
An example site config.toml:
	threshold = 1
	name = "keywords"
	weight = 200
	name  = "tags"
	weight = 100
	name  = "date"
	weight = 1
	pattern = "2006"

Here’s a great article from @regis about related content: https://regisphilibert.com/blog/2018/04/hugo-optmized-relashionships-with-related-content/

Regis’ post is awesome. Hadn’t seen it until reading the docs recently, where it’s linked.

It’s not clear in this thread if the OP was addressed though. Can they set category as index from config as seems to be indicated by @Hash_Borgir?

If not, and since you’ve already got the taxonomy, you can modify the following code (using the old method) which creates a see also list with a cap on the max number of results:


It won’t be as performant as the built-in but it won’t require you to add more taxonomy and at 270 odd posts you’re not going to notice much if any perceptible difference in speed.