add line wrapping to rustfmt
This commit is contained in:
parent
0f83e6122e
commit
e230e631d3
1
rustfmt.toml
Normal file
1
rustfmt.toml
Normal file
@ -0,0 +1 @@
|
|||||||
|
wrap_comments = true
|
@ -78,7 +78,8 @@ fn evaluate(query: &str, html: bool) -> Option<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the result was a single hex number then we add the decimal equivalent below
|
// if the result was a single hex number then we add the decimal equivalent
|
||||||
|
// below
|
||||||
if spans.len() == 1
|
if spans.len() == 1
|
||||||
&& spans[0].kind == fend_core::SpanKind::Number
|
&& spans[0].kind == fend_core::SpanKind::Number
|
||||||
&& spans[0].text.starts_with("0x")
|
&& spans[0].text.starts_with("0x")
|
||||||
@ -145,27 +146,6 @@ fn evaluate_into_spans(query: &str, multiline: bool) -> Vec<Span> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// // match queries like "ord(≿)" or just "≿"
|
|
||||||
// let re = regex!(
|
|
||||||
// r"^(?:(?:chr|charcode|char|charcode)(?:| for| of)\s*\(?\s*(\d+)\s*\)?)|(?:(\d+) (?:|to |into |as )(?:charcode|char|character))$"
|
|
||||||
// );
|
|
||||||
// if let Some(m) = re.captures(query) {
|
|
||||||
// if let Some(ord) = m
|
|
||||||
// .get(1)
|
|
||||||
// .or_else(|| m.get(2))
|
|
||||||
// .and_then(|m| m.as_str().parse::<u32>().ok())
|
|
||||||
// {
|
|
||||||
// let chr = std::char::from_u32(ord);
|
|
||||||
// if let Some(chr) = chr {
|
|
||||||
// return vec![Span {
|
|
||||||
// text: format!("'{chr}'"),
|
|
||||||
// kind: fend_core::SpanKind::String,
|
|
||||||
// }];
|
|
||||||
// } else {
|
|
||||||
// return vec![];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fend incorrectly triggers on these often
|
// fend incorrectly triggers on these often
|
||||||
{
|
{
|
||||||
@ -174,12 +154,14 @@ fn evaluate_into_spans(query: &str, multiline: bool) -> Vec<Span> {
|
|||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
|
|
||||||
// probably a query operator thing or a url, fend evaluates these but it shouldn't
|
// probably a query operator thing or a url, fend evaluates these but it
|
||||||
|
// shouldn't
|
||||||
if regex!("^[a-z]{2,}:").is_match(query) {
|
if regex!("^[a-z]{2,}:").is_match(query) {
|
||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it starts and ends with quotes then the person was just searching in quotes and didn't mean to evaluate a string
|
// if it starts and ends with quotes then the person was just searching in
|
||||||
|
// quotes and didn't mean to evaluate a string
|
||||||
if query.starts_with('"')
|
if query.starts_with('"')
|
||||||
&& query.ends_with('"')
|
&& query.ends_with('"')
|
||||||
&& query.chars().filter(|c| *c == '"').count() == 2
|
&& query.chars().filter(|c| *c == '"').count() == 2
|
||||||
|
@ -128,8 +128,9 @@ pub fn parse_response(HttpResponse { res, body }: &HttpResponse) -> eyre::Result
|
|||||||
|
|
||||||
fn key_to_title(key: &str) -> String {
|
fn key_to_title(key: &str) -> String {
|
||||||
// https://github.com/wikimedia/mediawiki-title
|
// https://github.com/wikimedia/mediawiki-title
|
||||||
// In general, the page title is converted to the mediawiki DB key format by trimming spaces,
|
// In general, the page title is converted to the mediawiki DB key format by
|
||||||
// replacing whitespace symbols to underscores and applying wiki-specific capitalization rules.
|
// trimming spaces, replacing whitespace symbols to underscores and applying
|
||||||
|
// wiki-specific capitalization rules.
|
||||||
|
|
||||||
let title = key.trim().replace('_', " ");
|
let title = key.trim().replace('_', " ");
|
||||||
let mut c = title.chars();
|
let mut c = title.chars();
|
||||||
|
@ -546,7 +546,8 @@ fn merge_engine_responses(responses: HashMap<Engine, EngineResponse>) -> Respons
|
|||||||
|
|
||||||
for (engine, response) in responses {
|
for (engine, response) in responses {
|
||||||
for (result_index, search_result) in response.search_results.into_iter().enumerate() {
|
for (result_index, search_result) in response.search_results.into_iter().enumerate() {
|
||||||
// position 1 has a score of 1, position 2 has a score of 0.5, position 3 has a score of 0.33, etc.
|
// position 1 has a score of 1, position 2 has a score of 0.5, position 3 has a
|
||||||
|
// score of 0.33, etc.
|
||||||
let base_result_score = 1. / (result_index + 1) as f64;
|
let base_result_score = 1. / (result_index + 1) as f64;
|
||||||
let result_score = base_result_score * engine.weight();
|
let result_score = base_result_score * engine.weight();
|
||||||
|
|
||||||
@ -554,7 +555,8 @@ fn merge_engine_responses(responses: HashMap<Engine, EngineResponse>) -> Respons
|
|||||||
.iter_mut()
|
.iter_mut()
|
||||||
.find(|r| r.url == search_result.url)
|
.find(|r| r.url == search_result.url)
|
||||||
{
|
{
|
||||||
// if the weight of this engine is higher than every other one then replace the title and description
|
// if the weight of this engine is higher than every other one then replace the
|
||||||
|
// title and description
|
||||||
if engine.weight()
|
if engine.weight()
|
||||||
> existing_result
|
> existing_result
|
||||||
.engines
|
.engines
|
||||||
@ -639,7 +641,8 @@ fn merge_autocomplete_responses(responses: HashMap<Engine, Vec<String>>) -> Vec<
|
|||||||
|
|
||||||
for (engine, response) in responses {
|
for (engine, response) in responses {
|
||||||
for (result_index, autocomplete_result) in response.into_iter().enumerate() {
|
for (result_index, autocomplete_result) in response.into_iter().enumerate() {
|
||||||
// position 1 has a score of 1, position 2 has a score of 0.5, position 3 has a score of 0.33, etc.
|
// position 1 has a score of 1, position 2 has a score of 0.5, position 3 has a
|
||||||
|
// score of 0.33, etc.
|
||||||
let base_result_score = 1. / (result_index + 1) as f64;
|
let base_result_score = 1. / (result_index + 1) as f64;
|
||||||
let result_score = base_result_score * engine.weight();
|
let result_score = base_result_score * engine.weight();
|
||||||
|
|
||||||
|
@ -22,7 +22,8 @@ pub fn parse_response(body: &str) -> eyre::Result<EngineResponse> {
|
|||||||
body,
|
body,
|
||||||
ParseOpts::new()
|
ParseOpts::new()
|
||||||
// xpd is weird, some results have it but it's usually used for ads?
|
// xpd is weird, some results have it but it's usually used for ads?
|
||||||
// the :first-child filters out the ads though since for ads the first child is always a span
|
// the :first-child filters out the ads though since for ads the first child is always a
|
||||||
|
// span
|
||||||
.result("div.g > div, div.xpd > div:first-child")
|
.result("div.g > div, div.xpd > div:first-child")
|
||||||
.title("h3")
|
.title("h3")
|
||||||
.href("a[href]")
|
.href("a[href]")
|
||||||
|
Loading…
Reference in New Issue
Block a user