Skip to content

web search done right

support both 'linkto:' and 'linksto:'

Mikkel Denker2bc0d69e009a
diff --git a/crates/core/src/query/mod.rs b/crates/core/src/query/mod.rs
index 9f7a66ad..0dfcda03 100644
--- a/crates/core/src/query/mod.rs
+++ b/crates/core/src/query/mod.rs
@@ -533,7 +533,7 @@ mod tests {
assert_eq!(result.webpages[0].url, "https://www.second.com/example/abc");
let query = SearchQuery {
- query: "test linksto:www.first.com".to_string(),
+ query: "test linkto:www.first.com".to_string(),
..Default::default()
};
let result = searcher.search(&query).expect("Search failed");
@@ -541,7 +541,7 @@ mod tests {
assert_eq!(result.webpages[0].url, "https://www.second.com/example/abc");
let query = SearchQuery {
- query: "test -linksto:first.com".to_string(),
+ query: "test -linkto:first.com".to_string(),
..Default::default()
};
let result = searcher.search(&query).expect("Search failed");
@@ -549,7 +549,7 @@ mod tests {
assert_eq!(result.webpages[0].url, "https://www.first.com/");
let query = SearchQuery {
- query: "test linksto:second.com".to_string(),
+ query: "test linkto:second.com".to_string(),
..Default::default()
};
let result = searcher.search(&query).expect("Search failed");
@@ -557,7 +557,7 @@ mod tests {
assert_eq!(result.webpages[0].url, "https://www.first.com/");
let query = SearchQuery {
- query: "test linksto:www.second.com".to_string(),
+ query: "test linkto:www.second.com".to_string(),
..Default::default()
};
let result = searcher.search(&query).expect("Search failed");
@@ -565,7 +565,7 @@ mod tests {
assert_eq!(result.webpages[0].url, "https://www.first.com/");
let query = SearchQuery {
- query: "test linksto:second.com/example".to_string(),
+ query: "test linkto:second.com/example".to_string(),
..Default::default()
};
let result = searcher.search(&query).expect("Search failed");
@@ -627,7 +627,7 @@ mod tests {
let searcher = LocalSearcher::from(index);
let query = SearchQuery {
- query: "test linksto:second.com".to_string(),
+ query: "test linkto:second.com".to_string(),
..Default::default()
};
let result = searcher.search(&query).expect("Search failed");
diff --git a/crates/core/src/query/parser/mod.rs b/crates/core/src/query/parser/mod.rs
index c92ca94e..5a10d5b1 100644
--- a/crates/core/src/query/parser/mod.rs
+++ b/crates/core/src/query/parser/mod.rs
@@ -124,7 +124,15 @@ fn links_to_field(input: &str) -> nom::IResult<&str, Term> {
let (input, _) = nom::bytes::complete::tag("linksto:")(input)?;
let (input, output) = simple_str(input)?;
- Ok((input, Term::LinksTo(output.to_string())))
+ Ok((input, Term::LinkTo(output.to_string())))
+}
+
+fn link_to_field(input: &str) -> nom::IResult<&str, Term> {
+ // parse 'linkto:' and then a simple term
+ let (input, _) = nom::bytes::complete::tag("linkto:")(input)?;
+ let (input, output) = simple_str(input)?;
+
+ Ok((input, Term::LinkTo(output.to_string())))
}
fn title_field(input: &str) -> nom::IResult<&str, Term> {
@@ -155,6 +163,7 @@ fn field_selector(input: &str) -> nom::IResult<&str, Term> {
nom::branch::alt((
site_field,
links_to_field,
+ link_to_field,
title_field,
body_field,
url_field,
diff --git a/crates/core/src/query/parser/term.rs b/crates/core/src/query/parser/term.rs
index 87047e8b..7eb26d31 100644
--- a/crates/core/src/query/parser/term.rs
+++ b/crates/core/src/query/parser/term.rs
@@ -98,7 +98,7 @@ impl std::fmt::Display for SimpleOrPhrase {
pub enum Term {
SimpleOrPhrase(SimpleOrPhrase),
Site(String),
- LinksTo(String),
+ LinkTo(String),
Title(SimpleOrPhrase),
Body(SimpleOrPhrase),
Url(SimpleOrPhrase),
@@ -112,7 +112,7 @@ impl std::fmt::Display for Term {
Term::SimpleOrPhrase(term) => write!(f, "{}", term),
Term::Not(term) => write!(f, "-{}", term),
Term::Site(site) => write!(f, "site:{}", site),
- Term::LinksTo(site) => write!(f, "linksto:{}", site),
+ Term::LinkTo(site) => write!(f, "linkto:{}", site),
Term::Title(title) => write!(f, "intitle:{}", title),
Term::Body(body) => write!(f, "inbody:{}", body),
Term::Url(url) => write!(f, "inurl:{}", url),
@@ -133,7 +133,7 @@ impl Term {
match self {
Term::SimpleOrPhrase(s) => Term::SimpleOrPhrase(s.truncate()),
Term::Site(s) => Term::Site(s),
- Term::LinksTo(s) => Term::LinksTo(s),
+ Term::LinkTo(s) => Term::LinkTo(s),
Term::Title(s) => Term::Title(s.truncate()),
Term::Body(s) => Term::Body(s.truncate()),
Term::Url(s) => Term::Url(s.truncate()),
diff --git a/crates/core/src/query/plan/node.rs b/crates/core/src/query/plan/node.rs
index 718a77dc..2840e221 100644
--- a/crates/core/src/query/plan/node.rs
+++ b/crates/core/src/query/plan/node.rs
@@ -131,7 +131,7 @@ impl Node {
text: SimpleOrPhrase::Simple(SimpleTerm::from(s)),
field: text_field::UrlForSiteOperator.into(),
}),
- ParserTerm::LinksTo(s) => Node::Term(Term {
+ ParserTerm::LinkTo(s) => Node::Term(Term {
text: SimpleOrPhrase::Simple(SimpleTerm::from(s)),
field: text_field::Links.into(),
}),