1
0
mirror of https://github.com/thangisme/notes.git synced 2024-12-22 14:36:51 -05:00
notes/docs/search.md

128 lines
3.2 KiB
Markdown
Raw Normal View History

2017-04-08 18:51:14 -04:00
---
layout: default
title: Search
2018-11-16 11:47:14 -05:00
nav_order: 7
2017-04-08 18:51:14 -04:00
---
# Search
2019-01-14 14:18:09 -05:00
{: .no_toc }
2018-12-16 14:47:41 -05:00
## Table of contents
{: .no_toc .text-delta }
1. TOC
{:toc}
---
2017-04-08 18:51:14 -04:00
Just the Docs uses [lunr.js](http://lunrjs.com) to add a client-side search interface powered by a JSON index that Jekyll generates.
All search results are shown in an auto-complete style interface (there is no search results page).
By default, all generated HTML pages are indexed using the following data points:
2017-04-08 18:51:14 -04:00
- Page title
- Page content
- Page URL
## Enable search in configuration
2018-11-16 11:47:30 -05:00
In your site's `_config.yml`, enable search:
2017-11-08 11:23:05 -05:00
```yaml
# Enable or disable the site search
# Supports true (default) or false
search_enabled: true
2017-11-08 11:23:05 -05:00
```
### Search granularity
2017-11-08 11:23:05 -05:00
Pages are split into sections that can be searched individually.
The sections are defined by the headings on the page.
Each section is displayed in a separate search result.
2017-11-08 11:23:05 -05:00
```yaml
# Split pages into sections that can be searched individually
# Supports 1 - 6, default: 2
search.heading_level: 2
```
2018-11-16 11:47:30 -05:00
### Search previews
2018-11-16 11:47:30 -05:00
A search result can contain previews that show where the search words are found in the specific section.
2018-11-16 11:47:30 -05:00
2019-01-15 20:43:19 -05:00
```yaml
# Maximum amount of previews per search result
# Default: 3
search.previews: 3
# Maximum amount of words to display before a matched word in the preview
# Default: 5
search.preview_words_before: 5
# Maximum amount of words to display after a matched word in the preview
# Default: 10
search.preview_words_after: 10
2018-11-16 11:47:30 -05:00
```
2018-12-16 14:47:41 -05:00
### Search tokenizer
The default is for hyphens to separate tokens in search terms:
`gem-based` is equivalent to `gem based`, matching either word.
To allow search for hyphenated words:
```yaml
# Set the search token separator
# Default: /[\s\-/]+/
# Example: enable support for hyphenated search words
search.tokenizer_separator: /[\s/]+/
```
### Display URL in search results
```yaml
# Display the relative url in search results
# Supports true (default) or false
search.rel_url: false
```
### Display search button
The search button displays in the bottom right corner of the screen and triggers the search input when clicked.
```yaml
# Enable or disable the search button that appears in the bottom right corner of every page
# Supports true or false (default)
search.button: true
```
2018-12-16 14:47:41 -05:00
## Hiding pages from search
Sometimes you might have a page that you don't want to be indexed for the search nor to show up in search results, e.g, a 404 page.
To exclude a page from search, add the `search_exclude: true` parameter to the page's YAML front matter:
2018-12-16 14:47:41 -05:00
#### Example
{: .no_toc }
2019-01-14 14:18:09 -05:00
2018-12-16 14:47:41 -05:00
```yaml
---
layout: default
title: Page not found
nav_exclude: true
search_exclude: true
---
```
2020-06-18 16:39:58 -04:00
## Generate search index when used as a gem
If you use Just the Docs as a remote theme, you do not need the following steps.
If you use the theme as a gem, you must initialize the search by running this `rake` command that comes with `just-the-docs`:
```bash
$ bundle exec just-the-docs rake search:init
```
This command creates the `assets/js/zzzz-search-data.json` file that Jekyll uses to create your search index.
Alternatively, you can create the file manually with [this content]({{ site.github.repository_url }}/blob/master/assets/js/zzzz-search-data.json).