Skip to content

web search done right

change host graph back to better be able to rank 'popular.domain.com' differently from 'not-as-popular.domain.com'

Mikkel Denkerb30310cc3a24
diff --git a/configs/api.toml b/configs/api.toml
index 2b9664d9..a87c5bf0 100644
--- a/configs/api.toml
+++ b/configs/api.toml
@@ -3,7 +3,7 @@ crossencoder_model_path = "data/cross_encoder"
gossip_addr = "0.0.0.0:3005"
gossip_seed_nodes = ["0.0.0.0:3006", "0.0.0.0:3007"]
host = "0.0.0.0:3000"
-lambda_model_path = "data/lambdamart.txt"
+# lambda_model_path = "data/lambdamart.txt"
prometheus_host = "0.0.0.0:3001"
queries_csv_path = "data/queries_us.csv"
spell_checker_path = "data/web_spell/checker"
diff --git a/configs/search_server.toml b/configs/search_server.toml
index c2a3898b..aee278bc 100644
--- a/configs/search_server.toml
+++ b/configs/search_server.toml
@@ -7,7 +7,7 @@ host_centrality_store_path = "data/centrality"
index_path = "data/index"
shard_id = 0
# linear_model_path = "data/linear_model.json"
-lambda_model_path = "data/lambdamart.txt"
+# lambda_model_path = "data/lambdamart.txt"
[snippet]
max_considered_words = 10_000
diff --git a/core/src/alice/mod.rs b/core/src/alice/mod.rs
index 1e97f6f2..9b70462f 100644
--- a/core/src/alice/mod.rs
+++ b/core/src/alice/mod.rs
@@ -53,6 +53,7 @@ use crate::{
llm_utils::ClonableTensor,
search_prettifier::DisplayedWebpage,
searcher::{SearchResult, WebsitesResult},
+ webpage::url_ext::UrlExt,
};
use self::{
@@ -114,7 +115,7 @@ impl SimplifiedWebsite {
Self {
title: webpage.title,
text,
- site: url.host_str().unwrap_or_default().to_string(),
+ site: url.normalized_host().unwrap_or_default().to_string(),
url: url.to_string(),
}
}
diff --git a/core/src/inverted_index.rs b/core/src/inverted_index.rs
index 56c6abc2..7820a432 100644
--- a/core/src/inverted_index.rs
+++ b/core/src/inverted_index.rs
@@ -51,6 +51,7 @@ use crate::tokenizer::{
};
use crate::webgraph::NodeID;
use crate::webpage::region::Region;
+use crate::webpage::url_ext::UrlExt;
use crate::webpage::{schema_org, Webpage};
use crate::Result;
use crate::{combine_u64s, snippet};
@@ -550,7 +551,9 @@ impl InvertedIndex {
.get_field(Field::Text(TextField::SiteIfHomepageNoTokenizer).name())
.unwrap();
- let term = tantivy::Term::from_field_text(field, url.host_str().unwrap_or_default());
+ let host = url.normalized_host().unwrap_or_default();
+
+ let term = tantivy::Term::from_field_text(field, host);
let query = tantivy::query::TermQuery::new(term, tantivy::schema::IndexRecordOption::Basic);
diff --git a/core/src/query/optic.rs b/core/src/query/optic.rs
index 6c3f40fb..32eeb0ae 100644
--- a/core/src/query/optic.rs
+++ b/core/src/query/optic.rs
@@ -700,9 +700,9 @@ mod tests {
optic: Some(
Optic::parse(
r#"
- Like(Domain("www.a.com"));
- Like(Domain("www.b.com"));
- Dislike(Domain("www.c.com"));
+ Like(Site("www.a.com"));
+ Like(Site("www.b.com"));
+ Dislike(Site("www.c.com"));
"#,
)
.unwrap(),
diff --git a/core/src/search_prettifier/mod.rs b/core/src/search_prettifier/mod.rs
index a9cf0a27..b0468f22 100644
--- a/core/src/search_prettifier/mod.rs
+++ b/core/src/search_prettifier/mod.rs
@@ -196,7 +196,7 @@ impl From<RetrievedWebpage> for DisplayedWebpage {
Self {
title: webpage.title,
- site: url.host_str().unwrap_or_default().to_string(),
+ site: url.normalized_host().unwrap_or_default().to_string(),
url: webpage.url,
pretty_url,
domain,
diff --git a/core/src/webgraph/mod.rs b/core/src/webgraph/mod.rs
index c973ceff..9c823f08 100644
--- a/core/src/webgraph/mod.rs
+++ b/core/src/webgraph/mod.rs
@@ -28,7 +28,6 @@ use utoipa::ToSchema;
use crate::executor::Executor;
use crate::intmap;
-use crate::webpage::url_ext::UrlExt;
pub mod centrality;
mod store;
@@ -184,7 +183,7 @@ impl Node {
match url {
Ok(url) => {
- let host = url.root_domain().unwrap_or_default().to_string();
+ let host = url.host_str().unwrap_or_default().to_string();
Node { name: host }
}
Err(_) => Node {
diff --git a/core/src/webpage/mod.rs b/core/src/webpage/mod.rs
index 99920dd1..0069b33f 100644
--- a/core/src/webpage/mod.rs
+++ b/core/src/webpage/mod.rs
@@ -932,17 +932,13 @@ impl Html {
}
fn pretokenize_domain(&self) -> PreTokenizedString {
- let mut domain = self.url().root_domain().unwrap_or_default().to_string();
-
- if let Some(stripped) = domain.strip_prefix("www.") {
- domain = stripped.to_string();
- }
+ let domain = self.url().root_domain().unwrap_or_default().to_string();
self.pretokenize_string(domain)
}
fn pretokenize_site(&self) -> PreTokenizedString {
- let site = self.url().host_str().unwrap_or_default().to_string();
+ let site = self.url().normalized_host().unwrap_or_default().to_string();
self.pretokenize_string(site)
}
@@ -1043,7 +1039,7 @@ impl Html {
},
};
- let site_hash = split_u128(hash(self.url().host_str().unwrap_or_default()).0);
+ let site_hash = split_u128(hash(self.url().normalized_host().unwrap_or_default()).0);
let mut url_without_query = self.url().clone();
url_without_query.set_query(None);
@@ -1463,9 +1459,9 @@ impl Html {
links
.into_iter()
- .filter(|link| link.host_str().is_some())
- .filter(|link| link.host_str() != self.url().host_str())
- .unique_by(|link| link.host_str().unwrap().to_string())
+ .filter(|link| link.normalized_host().is_some())
+ .filter(|link| link.normalized_host() != self.url().normalized_host())
+ .unique_by(|link| link.normalized_host().unwrap().to_string())
.collect()
}
diff --git a/core/src/webpage/url_ext.rs b/core/src/webpage/url_ext.rs
index 40311545..60f7eb67 100644
--- a/core/src/webpage/url_ext.rs
+++ b/core/src/webpage/url_ext.rs
@@ -30,6 +30,7 @@ static ICANN_LIST: once_cell::sync::Lazy<publicsuffix::List> = once_cell::sync::
pub trait UrlExt {
fn icann_domain(&self) -> Option<&str>;
fn root_domain(&self) -> Option<&str>;
+ fn normalized_host(&self) -> Option<&str>;
fn subdomain(&self) -> Option<&str>;
fn tld(&self) -> Option<&str>;
}
@@ -47,6 +48,10 @@ impl UrlExt for url::Url {
Some(suffix)
}
+ fn normalized_host(&self) -> Option<&str> {
+ self.host_str().map(|host| host.trim_start_matches("www."))
+ }
+
fn subdomain(&self) -> Option<&str> {
let domain = self.root_domain()?;
let host = self.host_str()?;
diff --git a/frontend/src/routes/search/+page.svelte b/frontend/src/routes/search/+page.svelte
index ceec3442..9c6058c9 100644
--- a/frontend/src/routes/search/+page.svelte
+++ b/frontend/src/routes/search/+page.svelte
@@ -98,7 +98,7 @@
const rankSite = (site: DisplayedWebpage, ranking: Ranking) => () => {
hostRankingsStore?.update(($rankings) => ({
...$rankings,
- [site.domain]: $rankings[site.domain] == ranking ? void 0 : ranking,
+ [site.site]: $rankings[site.site] == ranking ? void 0 : ranking,
}));
};
@@ -119,13 +119,13 @@
>
<div>
<h2 class="w-fit text-center">
- Do you like results from {modal.site.domain}?
+ Do you like results from {modal.site.site}?
</h2>
<div class="flex justify-center space-x-1.5 pt-2">
{#each rankingChoices as { ranking, kind, Icon }}
<Button
{kind}
- pale={$hostRankingsStore[modal.site.domain] != ranking}
+ pale={$hostRankingsStore[modal.site.site] != ranking}
padding={false}
form="searchbar-form"
on:click={rankSite(modal.site, ranking)}
diff --git a/frontend/src/routes/search/Discussions.svelte b/frontend/src/routes/search/Discussions.svelte
index 8123d2fe..cab85cfc 100644
--- a/frontend/src/routes/search/Discussions.svelte
+++ b/frontend/src/routes/search/Discussions.svelte
@@ -21,14 +21,14 @@
{#each shownDiscussions as discussion}
<div class="overflow-hidden">
<div>
- <a class="text-sm" href={discussion.url}>
+ <a class="text-sm text-neutral-focus" href={discussion.url}>
{discussion.domain}
</a>
</div>
<details class="group">
<summary class="flex cursor-pointer list-none items-center space-x-2">
<a
- class="text-md inline-block max-w-[calc(100%-10px)] truncate font-medium group-open:underline"
+ class="text-md text-neutral-focus inline-block max-w-[calc(100%-10px)] truncate font-medium group-open:underline"
title={discussion.title}
href={discussion.url}
>
diff --git a/frontend/src/themes/base.ts b/frontend/src/themes/base.ts
index 3b72e15f..1b7a9861 100644
--- a/frontend/src/themes/base.ts
+++ b/frontend/src/themes/base.ts
@@ -236,6 +236,7 @@ export const base = {
700: "#374151",
800: "#1F2937",
900: "#111827",
+ 950: "#0D131E",
},
neutral: {
50: "#FAFAFA",
diff --git a/frontend/src/themes/dark.ts b/frontend/src/themes/dark.ts
index 9195f4d6..76382e67 100644
--- a/frontend/src/themes/dark.ts
+++ b/frontend/src/themes/dark.ts
@@ -17,13 +17,13 @@ export const darkTheme = theme({
accentContent: '#fff',
neutral: base.zinc[400],
- neutralFocus: base.zinc[100],
+ neutralFocus: base.zinc[300],
neutralContent: base.zinc[300],
- base100: base.zinc[800],
- base200: base.zinc[700],
- base300: base.zinc[600],
- base400: base.zinc[500],
+ base100: base.zinc[900],
+ base200: base.zinc[800],
+ base300: base.zinc[700],
+ base400: base.zinc[600],
baseContent: base.island[50],
info: base.navy[600],
diff --git a/optics-lsp/package.json b/optics-lsp/package.json
index 87c9af5b..75034e11 100644
--- a/optics-lsp/package.json
+++ b/optics-lsp/package.json
@@ -1,6 +1,6 @@
{
"name": "Optics",
- "version": "0.0.10",
+ "version": "0.0.11",
"engines": {
"vscode": "^1.73.0"
},
diff --git a/optics-lsp/src/lib.rs b/optics-lsp/src/lib.rs
index 85bb9c83..18cc81e8 100644
--- a/optics-lsp/src/lib.rs
+++ b/optics-lsp/src/lib.rs
@@ -165,7 +165,8 @@ impl OpticsBackend {
A search result must match all the parts of the `Matches` block in order to match the specific rule.".to_string()),
optics::Token::Site => Some("`Site(\"...\")` matches any search result where the pattern defined in `\"...\"` matches the site of the result. \
- You can use `*` as a wildcard term and `|` to indicate either the end or start of a string. \n\
+ Note that when `Site` is used inside `Like` or `Dislike`, the pattern can only contain simple terms (no `*` and `|`). \n\n\
+ When the site is used in a `Matches` block, you can use `*` as a wildcard term and `|` to indicate either the end or start of a string. \n\
Consider the pattern `\"|sub.*.com|\"`. This will ensure that the terms `sub` and `.` must appear at the beggining of the site, then followed by any \
domain-name that ends in `.` and `com`. Note that `|` can only be used in the beggining or end of a pattern and the pattern will only match full terms (no substring matching). \n\n\
This example illustrates the difference between `Domain`, `Site` and `Url`:\n\
@@ -181,8 +182,7 @@ impl OpticsBackend {
".to_string()),
optics::Token::Domain => Some("`Domain(\"...\")` matches any search result where the pattern defined in `\"...\"` matches the domain of the result. \
- Note that when `Domain` is used inside `Like` or `Dislike`, the pattern can only contain simple terms (no `*` and `|`). \n\n\
- When the domain is used in a `Matches` block, you can use `*` as a wildcard term and `|` to indicate either the end or start of a domain. \n\
+ You can use `*` as a wildcard term and `|` to indicate either the end or start of a domain. \n\
Consider the pattern `\"example.org\"`. This is equivalent to doing a phrase search for `\"example.org\"` in the domain. Note that the pattern will only match full terms (no substring matching). \n\n\
This example illustrates the difference between `Domain`, `Site` and `Url`:\n\
Assume a search result has the url `https://sub.example.org/page`. the domain here is `example.org`, the site is `sub.example.org` and the url is the entire url (with protocol).\
@@ -230,11 +230,11 @@ impl OpticsBackend {
optics::Token::Discard => Some("`Discard` discards the matching search result completely from the results page.".to_string()),
- optics::Token::Like => Some("`Like(Domain(...))` lets you like specific hosts. During ranking, we will calculate a centrality meassure from all you liked sites \
+ optics::Token::Like => Some("`Like(Site(...))` lets you like specific hosts. During ranking, we will calculate a centrality meassure from all you liked sites \
so results that are heavily linked to from your liked sites will be favored. Note therefore, that `Like` not only alters the ranking of the specifc site, \
but also sites that are heavily linked to from the liked site.".to_string()),
- optics::Token::Dislike => Some("`Dislike(Domain(...))` lets you dislike specifc hosts. During ranking, we will calculate a centrality meassure from all you dislike sites \
+ optics::Token::Dislike => Some("`Dislike(Site(...))` lets you dislike specifc hosts. During ranking, we will calculate a centrality meassure from all you dislike sites \
so results that are heavily linked to from your disliked sites will be downranked. Note therefore, that `Dislike` not only alters the ranking of the specifc site, \
but also sites that are heavily linked to from the disliked site.".to_string()),
diff --git a/optics/src/lib.rs b/optics/src/lib.rs
index 1792676d..0c4f1d34 100644
--- a/optics/src/lib.rs
+++ b/optics/src/lib.rs
@@ -386,11 +386,11 @@ impl ToString for HostRankings {
let mut res = String::new();
for liked in &self.liked {
- res.push_str(&format!("Like(Domain(\"{}\"));\n", liked));
+ res.push_str(&format!("Like(Site(\"{}\"));\n", liked));
}
for disliked in &self.disliked {
- res.push_str(&format!("Dislike(Domain(\"{}\"));\n", disliked));
+ res.push_str(&format!("Dislike(Site(\"{}\"));\n", disliked));
}
for blocked in &self.blocked {
@@ -401,7 +401,7 @@ impl ToString for HostRankings {
PatternPart::Raw(blocked.clone()),
PatternPart::Anchor,
],
- location: MatchLocation::Domain,
+ location: MatchLocation::Site,
}],
action: Action::Discard,
};
@@ -417,6 +417,11 @@ impl HostRankings {
pub fn rules(&self) -> Vec<Rule> {
self.blocked
.iter()
+ .map(|host| {
+ host.strip_prefix("www.")
+ .map(|host| host.to_string())
+ .unwrap_or(host.clone())
+ })
.map(|host| Rule {
matches: vec![Matching {
pattern: vec![
@@ -424,7 +429,7 @@ impl HostRankings {
PatternPart::Raw(host.clone()),
PatternPart::Anchor,
],
- location: MatchLocation::Domain,
+ location: MatchLocation::Site,
}],
action: Action::Discard,
})
diff --git a/optics/src/parser.lalrpop b/optics/src/parser.lalrpop
index ed5606db..500ef16d 100644
--- a/optics/src/parser.lalrpop
+++ b/optics/src/parser.lalrpop
@@ -88,8 +88,8 @@ RankingTarget: RankingTarget = {
}
HostPreference: RawHostPreference = {
- "Like" "(" "Domain" "(" <StringLiteral> ")" ")" => RawHostPreference::Like(<>.to_string()),
- "Dislike" "(" "Domain" "(" <StringLiteral> ")" ")" => RawHostPreference::Dislike(<>.to_string())
+ "Like" "(" "Site" "(" <StringLiteral> ")" ")" => RawHostPreference::Like(<>.to_string()),
+ "Dislike" "(" "Site" "(" <StringLiteral> ")" ")" => RawHostPreference::Dislike(<>.to_string())
}
extern {
diff --git a/optics/testcases/samples b/optics/testcases/samples
index f80fc29f..ef0eba30 160000
--- a/optics/testcases/samples
+++ b/optics/testcases/samples
@@ -1 +1 @@
-Subproject commit f80fc29f4161f7c035d1f037b6b1365bfd7e045f
+Subproject commit ef0eba30c920012471bb1180a4acfc5824ae40bd