mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03: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 %}
|
||||
</div>
|
||||
{% 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(",") %}
|
||||
{% if languages | length and languages[0] != "" %}
|
||||
{% set path = base_url + "/assets/javascripts/lunr" %}
|
||||
|
@ -194,7 +194,17 @@ export default class Result {
|
||||
|
||||
/* Perform search on index and group sections by document */
|
||||
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) => {
|
||||
const doc = this.docs_.get(item.ref)
|
||||
if (doc.parent) {
|
||||
@ -209,7 +219,7 @@ export default class Result {
|
||||
|
||||
/* Assemble highlight regex from query string */
|
||||
const match = new RegExp(
|
||||
`(?:^|\\s)(${escape(this.value_.trim()).replace(" ", "|")})`, "img")
|
||||
`(?:^|\\b)(${escape(this.value_.trim()).replace(" ", "|")})`, "img")
|
||||
const highlight = string => `<em>${string}</em>`
|
||||
|
||||
/* Render results */
|
||||
|
Loading…
Reference in New Issue
Block a user