-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from tweedegolf/text-search-sorting
Text search sorting
- Loading branch information
Showing
9 changed files
with
79 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,52 @@ | ||
<script lang="ts"> | ||
import type {FullCrate} from "../crate-db"; | ||
import {sort_by, scores} from '../store/FilterStore.ts'; | ||
import Fuse from "fuse.js"; | ||
export let crates: FullCrate[]; | ||
export let selected: number[][]; | ||
interface Score { | ||
name: String; | ||
score: number; | ||
} | ||
let search: string = ""; | ||
const options = { | ||
keys: [ | ||
"description", | ||
"manufacturer", | ||
"name", | ||
{ | ||
name: "name", | ||
weight: 10, | ||
}, | ||
"names", | ||
"part_numbers", | ||
"resources.title", | ||
], | ||
includeMatches: true, | ||
includeScore: true, | ||
useExtendedSearch: true, | ||
useExtendedSearch: false, | ||
}; | ||
const index = Fuse.createIndex(options.keys, crates) | ||
const fuse = new Fuse(crates, options, index) | ||
const index = Fuse.createIndex(options.keys, crates); | ||
const fuse = new Fuse(crates, options, index); | ||
// Store the scores in the FilterStore on changes | ||
// and force sorting by score | ||
$ : { | ||
if (search.length > 0) { | ||
$sort_by = 'score'; | ||
$scores = (fuse.search(search).map((r) => ({ score: r.score, name: r.item.name } as Score))) as Score[]; | ||
} else { | ||
$sort_by = 'alphanumeric'; | ||
} | ||
} | ||
$: results = fuse.search(search) | ||
$: selected = search === "" ? [] : [results.map((r) => r.refIndex)] | ||
$: results = fuse.search(search); | ||
$: selected = search === "" ? [] : [results.map((r) => r.refIndex)]; | ||
</script> | ||
|
||
<div> | ||
<input type="text" bind:value={search}> | ||
</div> | ||
<input type="text" placeholder="Search" bind:value={search}> | ||
</div> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { writable } from "svelte/store"; | ||
|
||
export interface Score { | ||
name: String; | ||
score: number; | ||
} | ||
|
||
// Which filter is currenly opened | ||
export let open_filter = writable(""); | ||
|
||
// The results are sorted by | ||
export let sort_by = writable("alphanumeric"); | ||
|
||
// Results of text search | ||
export let scores = writable<Score[]>([]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters