Skip to content

web search done right

a bunch of frontend quirks. Also made frontend lighter by loading less static files unless they are needed

Mikkel Denker2cd5e6568b4d
diff --git a/core/src/api/search.rs b/core/src/api/search.rs
index 9635a816..49b38343 100644
--- a/core/src/api/search.rs
+++ b/core/src/api/search.rs
@@ -26,7 +26,7 @@ use crate::{
thousand_sep_number, CodeOrText, DisplayedAnswer, DisplayedWebpage,
HighlightedSpellCorrection, Sidebar, Snippet,
},
- searcher::{self, SearchQuery, SearchResult, NUM_RESULTS_PER_PAGE},
+ searcher::{self, SearchQuery, SearchResult, WebsitesResult, NUM_RESULTS_PER_PAGE},
webpage::region::{Region, ALL_REGIONS},
widgets::Widget,
Error,
@@ -59,8 +59,8 @@ struct SearchTemplate {
next_page_url: String,
prev_page_url: Option<String>,
default_optics: Vec<OpticLink>,
- current_optic_url: Option<String>,
has_more_results: bool,
+ has_code: bool,
}
enum RegionSelection {
@@ -105,15 +105,12 @@ pub async fn route(
.unwrap_or_default();
let mut optic = None;
- // should only be set if optic was successfully downloaded
- let mut current_optic_url = None;
if let Some(url) = params.get("optic") {
if !url.is_empty() {
if let Ok(res) = reqwest::get(url).await {
if let Ok(text) = res.text().await {
optic = Some(text);
- current_optic_url = Some(url.to_string());
}
}
}
@@ -152,6 +149,7 @@ pub async fn route(
let all_regions = generate_regions(selected_region);
let next_page_url = next_page_url(&uri, params.clone(), skip_pages);
let prev_page_url = prev_page_url(&uri, params, skip_pages);
+ let has_code = has_code(&result);
let current_page = skip_pages + 1;
@@ -170,8 +168,8 @@ pub async fn route(
next_page_url,
prev_page_url,
default_optics: DEFAULT_OPTICS.to_vec(),
- current_optic_url,
has_more_results: result.has_more_results,
+ has_code,
};
Ok(HtmlTemplate(template).into_response())
@@ -191,6 +189,17 @@ pub async fn route(
}
}
+fn has_code(result: &WebsitesResult) -> bool {
+ if let Some(Sidebar::StackOverflow { .. }) = result.sidebar.as_ref() {
+ return true;
+ }
+
+ result
+ .webpages
+ .iter()
+ .any(|page| matches!(page.snippet, Snippet::StackOverflowQA { .. }))
+}
+
fn generate_regions(selected_region: Option<Region>) -> Vec<RegionSelection> {
ALL_REGIONS
.into_iter()
diff --git a/frontend/src/components/Header.astro b/frontend/src/components/Header.astro
index 9b978158..bd5dbe20 100644
--- a/frontend/src/components/Header.astro
+++ b/frontend/src/components/Header.astro
@@ -11,7 +11,7 @@ const { icon = true, searchbar } = Astro.props;
---
<div
- class="grid h-24 grid-cols-[auto_1fr_auto] items-center p-4 sm:grid-cols-[3rem_1fr_auto] sm:gap-4 md:gap-5 lg:gap-10 lg:pr-8 lg:pl-14"
+ class="grid shrink-0 h-24 grid-cols-[auto_1fr_auto] items-center p-4 sm:grid-cols-[3rem_1fr_auto] sm:gap-4 md:gap-5 lg:gap-10 lg:pr-8 lg:pl-14"
>
{
icon && (
diff --git a/frontend/src/components/OpticSelector.astro b/frontend/src/components/OpticSelector.astro
index aa3d2440..c467a604 100644
--- a/frontend/src/components/OpticSelector.astro
+++ b/frontend/src/components/OpticSelector.astro
@@ -14,32 +14,35 @@ import { askama } from "$/askama";
name="optic"
onchange="document.getElementById('searchbar-form').submit()"
class="m-0 max-w-[100px] border-0 bg-transparent p-0 text-sm hover:cursor-pointer"
- x-data="{ items: $persist([]).as('optics') }"
>
<option value="">Optic</option>
{
askama.for_(
"optic in default_optics",
- askama.match("current_optic_url", {
- "Some(current_optic)": askama.if_(
- "current_optic == optic.url",
- () => (
- <option selected value="{{ optic.url }}">
- {askama`optic.name`}
- </option>
- ),
- () => <option value="{{ optic.url }}">{askama`optic.name`}</option>
- ),
- None: <option value="{{ optic.url }}">{askama`optic.name`}</option>,
- })
+ <option value="{{ optic.url }}">{askama`optic.name`}</option>
)
}
- <template x-for="item in items">
- <option x-value="item.url" x-text="item.name"></option>
- </template>
</select>
</div>
<script>
- import "$/alpine";
+ const optics: {url: string, name: string}[] = JSON.parse(window.localStorage.getItem("optics") || "[]");
+
+ for (const optic of optics) {
+ const option = document.createElement("option");
+ option.value = optic.url;
+ option.text = optic.name;
+ document.getElementById("optics-selector")!.appendChild(option);
+ }
+
+ var searchParams = new URLSearchParams(window.location.search);
+ const currentOpticUrl = searchParams.get("optic");
+
+ if (currentOpticUrl) {
+ Array.from(document.getElementById("optics-selector")!.getElementsByTagName("option")).forEach((option) => {
+ if (option.value === currentOpticUrl) {
+ option.selected = true;
+ }
+ });
+ }
</script>
\ No newline at end of file
diff --git a/frontend/src/layouts/Layout.astro b/frontend/src/layouts/Layout.astro
index 951825ee..fdf17e2a 100644
--- a/frontend/src/layouts/Layout.astro
+++ b/frontend/src/layouts/Layout.astro
@@ -24,7 +24,7 @@ const { title } = Astro.props;
<body class="font-light">
<slot />
- <style is:global>
+ <style>
html,
body {
position: relative;
diff --git a/frontend/src/pages/privacy-and-happy-lawyers.mdx b/frontend/src/pages/privacy-and-happy-lawyers.mdx
index 834933e4..1341a637 100644
--- a/frontend/src/pages/privacy-and-happy-lawyers.mdx
+++ b/frontend/src/pages/privacy-and-happy-lawyers.mdx
@@ -5,19 +5,30 @@ title: Privacy
# We will always respect your privacy.
-When using Stract, you can have peace of mind knowing that we do whatever is possible to keep your private information - private.
+When using Stract, you can have peace of mind knowing that we do everything possible to keep your private information the way it's supposed to be - private.
We mostly do this by simply not storing any of your private information at all. This keeps things simple, both for you and for us.
Here is a brief overview of your privacy:
-- Searches are anonymous and private to you.
- We don't store your IP address.
-- We do not use any web browser analytics or other frontend telemetry.
-- We do not share any user data with any third parties.
-- We collect only the data needed to provide and protect the service.
-- We serve all images and other static content directly from our servers to prevent tracking from third parties.
+- We don't store any information that can be used to fingerprint your device, browser etc.
+- We don't share any user data with any third parties.
+- We collect only the data needed to provide and improve the service.
+- We serve all content directly from our servers to prevent tracking from third parties.
- We use HTTPS encryption everywhere.
+By default, we do store some usage statistics in order to improve the search results. Specifically the following information is stored for each search:
+
+- The text used to perform the search.
+- The list of urls returned for the search.
+- Whether or not any of the results were clicked and if so, which one.
+- An id that is autogenerated and unique for each new search.
+- A timestamp rounded down to the nearest hour.
+
+This data is solely used to train our ranking models which improves the search results for everyone. We go to great lengths not to store anything
+that can tie your searches back to you or even figure out which searches were performed by the same individual.
+We hope you trust us with this limited data as it helps us improve our services tremendously. You can opt-out of this at any time from the [settings page](/settings/privacy) and we won't store anything at all.
+
You don't have to take our word for these claims as our [source code is available to everyone.](https://github.com/StractOrg/stract)
## Terms of Service
@@ -30,7 +41,7 @@ These Terms of Service ("Terms") govern your use of Stract (the "Services").
#### Privacy Policy
-We use the information we receive through the Services as described in our Privacy Policy.
+We use the information we receive through the Services as described in our Privacy Policy which can be found at the top of this site.
#### Source code
@@ -54,6 +65,11 @@ These Terms constitute the entire agreement between you and Stract concerning th
## Changelog
+#### 17-03-2023:
+
+Added which usage statistics are stored.
+
+
#### 22-09-2022:
Initial commit
diff --git a/frontend/src/pages/search.astro b/frontend/src/pages/search.astro
index bbaadd33..69635c49 100644
--- a/frontend/src/pages/search.astro
+++ b/frontend/src/pages/search.astro
@@ -221,8 +221,15 @@ import { askama } from "../askama";
</style>
</noscript>
-<link rel="stylesheet" href="/css/highlightjs-default.min.css" />
-<script is:inline src="/js/highlight.min.js"></script>
+{
+ askama.if_("has_code", () => {
+ <link rel="stylesheet" href="/css/highlightjs-default.min.css" />
+ <script is:inline src="/js/highlight.min.js"></script>
+ <script is:inline>
+ hljs.highlightAll();
+ </script>
+ })
+}
<script is:inline>
var rankingAdjustButtons = document.querySelectorAll(".adjust-btn");
var titleLinks = document.querySelectorAll(".sr-title-link");
@@ -253,7 +260,6 @@ import { askama } from "../askama";
"urls": urls
})
}).then((response) => response.text()).then((data) => {
- console.log(data);
qid = data;
});
}
@@ -296,6 +302,3 @@ import { askama } from "../askama";
}
}
</script>
-<script is:inline>
- hljs.highlightAll();
-</script>
diff --git a/frontend/src/pages/settings/index.astro b/frontend/src/pages/settings/index.astro
index c805cb26..fa5d351e 100644
--- a/frontend/src/pages/settings/index.astro
+++ b/frontend/src/pages/settings/index.astro
@@ -5,23 +5,25 @@ import { askama } from "../../askama";
<SettingsLayout>
<div>
- <h1 class="text-2xl font-medium">Manage Optics</h1>
- <div class="mt-5 text-sm">
- Optics lets you control almost everything about which search results
- that gets returned to you. You can discard results from specific
- sites, boost results from other sites and much more.
- </div>
- <div class="mt-3 text-sm">
- See our <a
- href="https://github.com/StractOrg/sample-optics/blob/main/quickstart.optic"
- >quickstart</a
- > for how to get started. Once you have developed your optic, you can add
- it here to be used during your search.
- </div>
- <div class="mt-3 text-sm">
- Simply host the optic on a url that returns a plain-text HTTP response
- with the optic. We use raw.githubusercontent.com, but you are free to
- host them elsewhere.
+ <div class="space-y-3">
+ <h1 class="text-2xl font-medium">Manage Optics</h1>
+ <div class="text-sm">
+ Optics lets you control almost everything about which search results
+ that gets returned to you. You can discard results from specific
+ sites, boost results from other sites and much more.
+ </div>
+ <div class="text-sm">
+ See our <a
+ href="https://github.com/StractOrg/sample-optics/blob/main/quickstart.optic"
+ >quickstart</a
+ > for how to get started. Once you have developed your optic, you can add
+ it here to be used during your search.
+ </div>
+ <div class="text-sm">
+ Simply host the optic on a url that returns a plain-text HTTP response
+ with the optic. We use raw.githubusercontent.com, but you are free to
+ host them elsewhere.
+ </div>
</div>
<div
class="mt-16"
@@ -77,4 +79,4 @@ import { askama } from "../../askama";
<script>
import "$/alpine";
-</script>
+</script>
\ No newline at end of file
diff --git a/frontend/src/pages/settings/privacy.astro b/frontend/src/pages/settings/privacy.astro
index d8721927..d820914e 100644
--- a/frontend/src/pages/settings/privacy.astro
+++ b/frontend/src/pages/settings/privacy.astro
@@ -2,7 +2,7 @@
import SettingsLayout from "../../layouts/Settings.astro";
---
<SettingsLayout>
- <div class="flex flex-col space-y-2">
+ <div class="flex flex-col space-y-3">
<h1 class="text-2xl font-medium">Privacy</h1>
<div class="text-sm">
By default, some data about your searches are stored on our servers. We primarily store the text you used for the search, and which results (if any) you clicked on.
diff --git a/frontend/src/pages/settings/sites.astro b/frontend/src/pages/settings/sites.astro
index a23828cb..ea8fe308 100644
--- a/frontend/src/pages/settings/sites.astro
+++ b/frontend/src/pages/settings/sites.astro
@@ -5,12 +5,11 @@ import SettingsLayout from "../../layouts/Settings.astro";
<div>
<h1 class="mb-2 text-2xl font-medium">Liked Sites</h1>
<div class="text-sm">
- These sites receive a boost during search. Results from these and similar sites
- are more likely to appear in your search results.
+ Sites that are similar to these sites receive a boost during search. Their results are more likely to appear in your search results.
</div>
- <div class="mt-5">
+ <div>
<div
- class="grid w-full grid-cols-[auto_1fr] space-y-5"
+ class="grid mb-10 w-full grid-cols-[auto_1fr] space-y-5"
id="liked-list"
>
<div class="w-10"></div>
@@ -22,12 +21,11 @@ import SettingsLayout from "../../layouts/Settings.astro";
<div>
<h1 class="mb-2 text-2xl font-medium">Disliked Sites</h1>
<div class="text-sm">
- These sites get de-prioritized during search. Results from these and similar
- sites are less likely to appear in your search results.
+ Sites that are similar to these sites gets de-prioritized during search. Their results are less likely to appear in your search results.
</div>
- <div class="mt-5">
+ <div>
<div
- class="grid w-full grid-cols-[auto_1fr] space-y-5"
+ class="grid mb-10 w-full grid-cols-[auto_1fr] space-y-5"
id="disliked-list"
>
<div class="w-10"></div>
@@ -42,9 +40,9 @@ import SettingsLayout from "../../layouts/Settings.astro";
These are the sites you have blocked. They won't appear in any of
your searches.
</div>
- <div class="mt-5">
+ <div>
<div
- class="grid w-full grid-cols-[auto_1fr] space-y-5"
+ class="grid mb-10 w-full grid-cols-[auto_1fr] space-y-5"
id="blocked-list"
>
<div class="w-10"></div>