mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2025-02-06 14:14:23 +01:00
Improved search matching and highlighting
This commit is contained in:
parent
4887a7e062
commit
357c6f4122
File diff suppressed because one or more lines are too long
@ -150,7 +150,7 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script src="{{ base_url }}/assets/javascripts/application-b4eb7a00cd.js"></script>
|
<script src="{{ base_url }}/assets/javascripts/application-8ec1c9e2d8.js"></script>
|
||||||
{% set languages = lang.t("search.languages").split(",") %}
|
{% set languages = lang.t("search.languages").split(",") %}
|
||||||
{% if languages | length and languages[0] != "" %}
|
{% if languages | length and languages[0] != "" %}
|
||||||
{% set path = base_url + "/assets/javascripts/lunr" %}
|
{% set path = base_url + "/assets/javascripts/lunr" %}
|
||||||
|
@ -194,7 +194,17 @@ export default class Result {
|
|||||||
|
|
||||||
/* Perform search on index and group sections by document */
|
/* Perform search on index and group sections by document */
|
||||||
const result = this.index_
|
const result = this.index_
|
||||||
.search(this.value_)
|
|
||||||
|
/* Append trailing wildcard to all terms for prefix querying */
|
||||||
|
.query(query => {
|
||||||
|
this.value_.split(" ")
|
||||||
|
.filter(Boolean)
|
||||||
|
.forEach(term => {
|
||||||
|
query.term(term, { wildcard: lunr.Query.wildcard.TRAILING })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Process query results */
|
||||||
.reduce((items, item) => {
|
.reduce((items, item) => {
|
||||||
const doc = this.docs_.get(item.ref)
|
const doc = this.docs_.get(item.ref)
|
||||||
if (doc.parent) {
|
if (doc.parent) {
|
||||||
@ -209,7 +219,7 @@ export default class Result {
|
|||||||
|
|
||||||
/* Assemble highlight regex from query string */
|
/* Assemble highlight regex from query string */
|
||||||
const match = new RegExp(
|
const match = new RegExp(
|
||||||
`(?:^|\\s)(${escape(this.value_.trim()).replace(" ", "|")})`, "img")
|
`(?:^|\\b)(${escape(this.value_.trim()).replace(" ", "|")})`, "img")
|
||||||
const highlight = string => `<em>${string}</em>`
|
const highlight = string => `<em>${string}</em>`
|
||||||
|
|
||||||
/* Render results */
|
/* Render results */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user