Skip to content

web search done right

Remove 'sr' parameter (#215)

Mikkel Denkeree516eff9559
diff --git a/frontend/package.json b/frontend/package.json
index 77c7a076..db2d8123 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -62,7 +62,6 @@
"colord": "^2.9.3",
"file-saver": "^2.0.5",
"highlight.js": "^11.9.0",
- "lz-string": "^1.5.0",
"tailwind-merge": "^2.1.0",
"ts-pattern": "^5.0.6",
"client-wasm": "file:../crates/client-wasm/pkg"
diff --git a/frontend/src/lib/components/Searchbar.svelte b/frontend/src/lib/components/Searchbar.svelte
index a83e9697..f1df8845 100644
--- a/frontend/src/lib/components/Searchbar.svelte
+++ b/frontend/src/lib/components/Searchbar.svelte
@@ -4,10 +4,8 @@
import MagnifyingGlass from '~icons/heroicons/magnifying-glass';
import Button from '$lib/components/Button.svelte';
import { api, type HighlightedFragment } from '$lib/api';
- import { safeSearchStore, hostRankingsStore, postSearchStore } from '$lib/stores';
+ import { safeSearchStore, postSearchStore } from '$lib/stores';
import { browser } from '$app/environment';
- import { derived } from 'svelte/store';
- import { compressRanked, rankingsToRanked } from '$lib/rankings';
import { twJoin } from 'tailwind-merge';
import { P, match } from 'ts-pattern';
@@ -40,10 +38,6 @@
$: if (didChangeInput) lastRealQuery = query;
$: if (browser) updateSuggestions(lastRealQuery);
- const compressedRanked = derived(hostRankingsStore, ($host_rankings) =>
- compressRanked(rankingsToRanked($host_rankings)),
- );
-
const selectSuggestion = (s: HighlightedFragment[]) => (query = suggestionText(s));
const moveSelection = (step: number) => {
@@ -102,7 +96,6 @@
bind:this={formElem}
>
<input type="hidden" value={$safeSearchStore ? 'true' : 'false'} name="ss" />
- <input type="hidden" value={$compressedRanked} name="sr" id="host_rankingsUuid" />
<label
for="searchbar"
diff --git a/frontend/src/lib/rankings.ts b/frontend/src/lib/rankings.ts
index bbdab8ae..a5a04b93 100644
--- a/frontend/src/lib/rankings.ts
+++ b/frontend/src/lib/rankings.ts
@@ -1,5 +1,3 @@
-import LZString from 'lz-string';
-
export type Ranking = 'liked' | 'disliked' | 'blocked';
export const Rankings = ['liked', 'disliked', 'blocked'] as Ranking[];
@@ -31,8 +29,3 @@ export const rankedToRankings = (ranked: RankedSites): SiteRankings => {
return result;
};
-
-export const compressRanked = (ranked: RankedSites): string =>
- LZString.compressToBase64(JSON.stringify(ranked));
-export const decompressRanked = (compressedRanked: string): RankedSites =>
- JSON.parse(LZString.decompressFromBase64(compressedRanked));
diff --git a/frontend/src/lib/search.ts b/frontend/src/lib/search.ts
index 5a3d574d..fb30f080 100644
--- a/frontend/src/lib/search.ts
+++ b/frontend/src/lib/search.ts
@@ -10,7 +10,7 @@ import {
api,
} from './api';
import { fetchRemoteOptic } from './optics';
-import { decompressRanked, type RankedSites } from './rankings';
+import { type RankedSites } from './rankings';
export type SearchParams = {
query: string;
@@ -18,7 +18,6 @@ export type SearchParams = {
optic: string | undefined;
selectedRegion: Region | undefined;
safeSearch: boolean;
- compressedHostRankings: string | null;
hostRankings: RankedSites | undefined;
showRankingSignals?: boolean;
};
@@ -43,10 +42,6 @@ export const extractSearchParams = (searchParams: URLSearchParams | FormData): S
| Region
| undefined;
const safeSearch = (searchParams.get('ss') as string | undefined) == 'true';
- const compressedhost_rankings = (searchParams.get('sr') as string | undefined) || null;
- const host_rankings = compressedhost_rankings
- ? decompressRanked(compressedhost_rankings)
- : void 0;
return {
query,
@@ -54,8 +49,7 @@ export const extractSearchParams = (searchParams: URLSearchParams | FormData): S
optic,
selectedRegion,
safeSearch,
- compressedHostRankings: compressedhost_rankings,
- hostRankings: host_rankings,
+ hostRankings: undefined,
};
};
diff --git a/frontend/src/routes/search/+page.svelte b/frontend/src/routes/search/+page.svelte
index 0cad86b9..d3bd102e 100644
--- a/frontend/src/routes/search/+page.svelte
+++ b/frontend/src/routes/search/+page.svelte
@@ -3,7 +3,12 @@
import Searchbar from '$lib/components/Searchbar.svelte';
import type { PageData } from './$types';
import RegionSelect from '$lib/components/RegionSelect.svelte';
- import { searchQueryStore, showRankingSignals, useKeyboardShortcuts } from '$lib/stores';
+ import {
+ searchQueryStore,
+ showRankingSignals,
+ useKeyboardShortcuts,
+ hostRankingsStore,
+ } from '$lib/stores';
import { page } from '$app/stores';
import { updateQueryId } from '$lib/improvements';
import { browser } from '$app/environment';
@@ -14,6 +19,8 @@
import SpellCorrection from './SpellCorrection.svelte';
import type { Count } from '$lib/api';
import { match } from 'ts-pattern';
+ import { rankingsToRanked, type RankedSites } from '$lib/rankings';
+ import { derived } from 'svelte/store';
export let data: PageData;
$: results = data.results;
@@ -42,12 +49,17 @@
let serp: Serp | undefined = undefined;
- const clientSearch = async () => {
+ const hostRankings = derived(hostRankingsStore, (rankings) => {
+ return rankingsToRanked(rankings);
+ });
+
+ const clientSearch = async (hostRankings: RankedSites) => {
if (!browser) return;
const params = {
...data.params,
showRankingSignals: $showRankingSignals,
+ hostRankings,
};
const res = await search(params, { fetch: fetch });
@@ -119,6 +131,8 @@
})
.exhaustive();
};
+
+ $: clientResults = clientSearch($hostRankings);
</script>
<svelte:window on:keydown={onKeyDown} />
@@ -173,7 +187,7 @@
bind:this={serp}
/>
{:else}
- {#await clientSearch() then results}
+ {#await clientResults then results}
{#if results}
<Serp
{results}