rust-search-extension/README.md

85 lines
2.6 KiB
Markdown
Raw Normal View History

2018-11-27 03:34:35 +00:00
![](assets/rustacean.png)
2018-10-31 11:40:46 +00:00
2018-11-27 03:34:35 +00:00
# Rust Search Extension
![Chrome Web Store](https://img.shields.io/chrome-web-store/v/)
[![license-mit](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Folyd/rust-search-extension/blob/master/LICENSE-MIT)
[![license-apache](https://img.shields.io/badge/license-Apache-yellow.svg)](https://github.com/Folyd/rust-search-extension/blob/master/LICENSE-APACHE)
A handy browser extension to search crates and docs in address bar (omnibox).
### Features
- Search Primitive Types and Modules
- Search Structs, Traits and Enums
- Search Functions, Methods and Macros
- Search crates on https://crates.io
### Usages
Input keyword **rs** in address bar, press `Tab` or `Space` to active the search bar.
Then enter any word you want to search, the extension will response the related search
results in few seconds.
![demonstration.gif](assets/demonstration.gif)
### How the extension works
##### 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.rs](https://github.com/rust-lang/rust/blob/master/src/librustdoc/html/render.rs).
The final *search index* is a object array like this:
```js
var searchIndex = [
{
crate: "std",
desc: "The `Option` type. See the module level documentation for more.",
displayPath: "std::option::",
fullPath: "std::option::Option",
href: "https://doc.rust-lang.org/std/option/enum.Option.html",
lev: 0,
name: "Option",
parent: undefined,
path: "std::option",
ty: 4,
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",
"disply",
"debug",
...
]
```
##### 3. Search keyword in *search words array* by *levenshtein distance*, mapping the *search word* and *search index* to generate the *search result*
##### 4. Sort *search result* according to *levenshtein distance* and others metrics
##### 5. Transform *search result* to *suggestion result* to show in address bar