mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-15 08:07:08 +00:00
Replace How-it-works link with Blog
This commit is contained in:
parent
98c387215f
commit
2bee533013
2 changed files with 1 additions and 93 deletions
|
@ -1,93 +0,0 @@
|
|||
+++
|
||||
title = "How it works"
|
||||
description = "How it works"
|
||||
weight = 1
|
||||
+++
|
||||
|
||||
# Search std docs
|
||||
|
||||
## 1. Build *search index*
|
||||
|
||||
The raw *search index* was generated by **rustc-doc**. The most important function is `build_index()` which
|
||||
located at [librustdoc/html/render/cache.rs](https://github.com/rust-lang/rust/blob/master/src/librustdoc/html/render/cache.rs).
|
||||
|
||||
The final *search index* is an object array like this:
|
||||
|
||||
```js
|
||||
var searchIndex = [
|
||||
{
|
||||
crate: "std",
|
||||
desc: "A hash map implemented with linear probing and Robin Hood bucket stealing.",
|
||||
name: "HashMap",
|
||||
parent: undefined,
|
||||
path: "std::collections",
|
||||
ty: 3,
|
||||
type: null
|
||||
},
|
||||
{
|
||||
crate: "std",
|
||||
desc: "Applies function to the elements of iterator and returns the first non-none result.",
|
||||
name: "find_map",
|
||||
parent: {ty: 8, name: "Iterator"},
|
||||
path: "std::iter",
|
||||
ty: 11,
|
||||
type: [["self"],["f"]]
|
||||
},
|
||||
...
|
||||
];
|
||||
```
|
||||
|
||||
## 2. Build *search words array* based on *search index*
|
||||
|
||||
The *search words array* is the list of search words to query against which build from the raw *search index*.
|
||||
It's just a plain name array of every Rust structs, traits, enums, functions, methods, macros, etc.
|
||||
```js
|
||||
var searchWords = [
|
||||
"result",
|
||||
"option",
|
||||
"hashmap",
|
||||
"hashset",
|
||||
"clone",
|
||||
"copy",
|
||||
"display",
|
||||
"debug",
|
||||
...
|
||||
];
|
||||
```
|
||||
|
||||
## 3. Search keyword in *search words array*
|
||||
|
||||
Using *Levenshtein distance* algorithm to search matched words, the max Levenshtein distance is 2.
|
||||
|
||||
```js
|
||||
// Max levenshtein distance.
|
||||
var MAX_LEV_DISTANCE = 2;
|
||||
```
|
||||
|
||||
## 4. Sort *search result*
|
||||
|
||||
Sort search result according to *Levenshtein distance*, lexicographical and others metrics.
|
||||
|
||||
## 5. Transform *search result* to *suggestion result* to show in the address bar
|
||||
|
||||
Mapping the *search word* and *search index* to generate the *search result*, build Rust doc link for each result item.
|
||||
|
||||
```js
|
||||
var suggestResults = [
|
||||
{
|
||||
content: "https://doc.rust-lang.org/std/ops/trait.Deref.html",
|
||||
description: "std::ops::<match>Deref</match> - <dim>Used for immutable dereferencing operations, like `*v`.</dim>"
|
||||
},
|
||||
{
|
||||
content: "https://doc.rust-lang.org/std/ops/trait.Deref.html#tymethod.deref",
|
||||
description: "std::ops::Deref::<match>deref</match> - <dim>Dereferences the value.</dim>"
|
||||
},
|
||||
...
|
||||
];
|
||||
```
|
||||
|
||||
# Search crates on crates.io
|
||||
|
||||
## 1. Build crates index
|
||||
|
||||
To be done...
|
1
docs/templates/_macros.html
vendored
1
docs/templates/_macros.html
vendored
|
@ -8,6 +8,7 @@
|
|||
</a>
|
||||
|
||||
<nav>
|
||||
<a class="nav-item subtitle-text" href="https://blog.huhu.io">Blog</a>
|
||||
{% for page in section.pages %}
|
||||
<a class="nav-item subtitle-text" href="{{ page.permalink }}">{{ page.title }}</a>
|
||||
{% endfor %}
|
||||
|
|
Loading…
Reference in a new issue