Building search index with title and description only

Hello there!
I’m newbie in Zola, and first, many thanks Vincent and other for the cool engine. It’s awesome!

I have a small question about search index building. If you have 1000 pages it’s would be nightmare to get all texts in search file, might zola or lunr have any mechanism to limit search index with titles and descriptions only?

Thank you!

No way to do that currently no :slightly_frowning_face:

If you really have thousands of pages, it’s probably better to not have your search be done in JS like that anyway as the results are not going to be great when based only on name/description. The JS index might get pretty big as well. The Zola docs site for example is pretty small but the index is already 600kb

2 Likes

I can’t test it, but what if I change in components/search/src/lib.rs string

let mut index = Index::with_language(language, &[“title”, “body”]);

to

let mut index = Index::with_language(language, &[“title”, “description”]);

'cause poor search better than no search :slight_smile:

1 Like

for future searchers it didn’t work :slight_smile:

What was the issue?

Search index had the same size anyway, but search works on titles only. Maybe I missed something, and it needs to be fixed somewhere else

Did you update the JavaScript to edit the elasticlunr options? By default it uses the keys title & body, you probably need to set description instead of body.

unfortunately, it’s not about JS, I got search index with full content but the string named “description”

Bu I’ll try to create “title only” index, maybe it works

I’m back :slight_smile:

So, if I delete “body” search index are built with titles only. It’s good. But I need my descriptions too! :slight_smile:

I saw mdbook’s code and they build search index with title, body and breadcrumbs. And I don’t understand how they declare a variable breadcrumbs? Do I need to add something to the top of the search lib?

You can add anything you want in the index. I don’t use mdbook so I can’t say what breadcrumbs are in their context but right now, its just that Zola only uses title and body to search.

1 Like

I suggested you was inspired by mdbook when you implemented search, sorry for bothering you, I’ll try to understand how to craft it as I want

You can add whatever you want to add to the index in https://github.com/getzola/zola/blob/master/components/search/src/lib.rs#L69-L70 and https://github.com/getzola/zola/blob/master/components/search/src/lib.rs#L84-L85

Oh, I ain’t a developer and have a lack of experience with RUST. So easy, many thanks! it works, i’ve just added &page.meta.description.clone().unwrap_or_default(), and search_index built properly as I want!