Skip to content

Commit 976c6b2

Browse files
authored
Rollup merge of #90630 - GuillaumeGomez:improve-rustdoc-search, r=notriddle
Create real parser for search queries You can test it [here](https://rustdoc.crud.net/imperio/improve-rustdoc-search/std/index.html). This PR adds a real parser for the query engine in rustdoc. The parser is quite simple but it allows to makes query handling much easier. I added a new testsuite to ensure it works as expected and ran fuzzing checks on it for a few hours without problems. So about the parser: as you can see in the screenshot, it handles recursive generics parsing. It also allows to set which item should use exact matching by adding double-quotes around it (look for `exact_search` in the screenshot). Now about the query engine itself: I simplified it a lot thanks to the parsed query. It behaves mostly the same when there is only one argument, but is much more powerful when there are more than one. When making this change, we also removed the support for multi-query. PS: A big part of the PR is tests and test-related code. :) r? `@camelid`
2 parents 51ea9bb + 4d26bde commit 976c6b2

21 files changed

+2299
-457
lines changed

src/librustdoc/html/static/js/externs.js

+55-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,34 @@ function initSearch(searchIndex){}
88

99
/**
1010
* @typedef {{
11-
* raw: string,
12-
* query: string,
13-
* type: string,
14-
* id: string,
11+
* name: string,
12+
* fullPath: Array<string>,
13+
* pathWithoutLast: Array<string>,
14+
* pathLast: string,
15+
* generics: Array<QueryElement>,
16+
* }}
17+
*/
18+
var QueryElement;
19+
20+
/**
21+
* @typedef {{
22+
* pos: number,
23+
* totalElems: number,
24+
* typeFilter: (null|string),
25+
* userQuery: string,
26+
* }}
27+
*/
28+
var ParserState;
29+
30+
/**
31+
* @typedef {{
32+
* original: string,
33+
* userQuery: string,
34+
* typeFilter: number,
35+
* elems: Array<QueryElement>,
36+
* args: Array<QueryElement>,
37+
* returned: Array<QueryElement>,
38+
* foundElems: number,
1539
* }}
1640
*/
1741
var ParsedQuery;
@@ -30,3 +54,30 @@ var ParsedQuery;
3054
* }}
3155
*/
3256
var Row;
57+
58+
/**
59+
* @typedef {{
60+
* in_args: Array<Object>,
61+
* returned: Array<Object>,
62+
* others: Array<Object>,
63+
* query: ParsedQuery,
64+
* }}
65+
*/
66+
var ResultsTable;
67+
68+
/**
69+
* @typedef {{
70+
* desc: string,
71+
* displayPath: string,
72+
* fullPath: string,
73+
* href: string,
74+
* id: number,
75+
* lev: number,
76+
* name: string,
77+
* normalizedName: string,
78+
* parent: (Object|undefined),
79+
* path: string,
80+
* ty: number,
81+
* }}
82+
*/
83+
var Results;

0 commit comments

Comments
 (0)