mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2026-07-23 22:33:42 -04:00
Added search templates + filtered rogue quantifiers
This commit is contained in:
@@ -23,9 +23,9 @@
|
||||
import * as lunr from "lunr"
|
||||
|
||||
import {
|
||||
SearchArticle,
|
||||
ArticleDocument,
|
||||
SearchDocumentMap,
|
||||
SearchSection,
|
||||
SectionDocument,
|
||||
setupSearchDocumentMap
|
||||
} from "../document"
|
||||
|
||||
@@ -79,8 +79,8 @@ export interface SearchIndex {
|
||||
* Search result
|
||||
*/
|
||||
export interface SearchResult {
|
||||
article: SearchArticle /* Relevant article */
|
||||
sections: SearchSection[] /* Relevant sections */
|
||||
article: ArticleDocument /* Article document */
|
||||
sections: SectionDocument[] /* Section documents */
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
@@ -176,7 +176,9 @@ export class Search {
|
||||
* @return Search results
|
||||
*/
|
||||
public search(query: string): SearchResult[] {
|
||||
const groups = this.index.search(query)
|
||||
const groups = this.index.search(query
|
||||
.replace(/\s+[+-](?:\s+|$)/, "") /* Filter rogue quantifiers */
|
||||
)
|
||||
|
||||
/* Group sections by containing article */
|
||||
.reduce((results, result) => {
|
||||
@@ -195,9 +197,9 @@ export class Search {
|
||||
|
||||
/* Map groups to search documents */
|
||||
return [...groups].map(([ref, sections]) => ({
|
||||
article: this.documents.get(ref) as SearchArticle,
|
||||
article: this.documents.get(ref) as ArticleDocument,
|
||||
sections: sections.map(section => {
|
||||
return this.documents.get(section.ref) as SearchSection
|
||||
return this.documents.get(section.ref) as SectionDocument
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -31,15 +31,15 @@ import { SearchIndexDocument } from "../_"
|
||||
/**
|
||||
* A top-level article
|
||||
*/
|
||||
export interface SearchArticle extends SearchIndexDocument {
|
||||
export interface ArticleDocument extends SearchIndexDocument {
|
||||
section: boolean /* Whether the section was linked */
|
||||
}
|
||||
|
||||
/**
|
||||
* A section of an article
|
||||
*/
|
||||
export interface SearchSection extends SearchIndexDocument {
|
||||
article: SearchArticle /* Parent article */
|
||||
export interface SectionDocument extends SearchIndexDocument {
|
||||
article: ArticleDocument /* Parent article */
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@@ -48,8 +48,8 @@ export interface SearchSection extends SearchIndexDocument {
|
||||
* Search document
|
||||
*/
|
||||
export type SearchDocument =
|
||||
| SearchArticle
|
||||
| SearchSection
|
||||
| ArticleDocument
|
||||
| SectionDocument
|
||||
|
||||
/**
|
||||
* Search document mapping
|
||||
@@ -85,7 +85,7 @@ export function setupSearchDocumentMap(
|
||||
|
||||
/* Handle section */
|
||||
if (hash) {
|
||||
const article = documents.get(path) as SearchArticle
|
||||
const article = documents.get(path) as ArticleDocument
|
||||
|
||||
/* Ignore first section, override article */
|
||||
if (!article.section) {
|
||||
|
||||
Reference in New Issue
Block a user