-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(search): switches to fuzzy search
- Loading branch information
Showing
8 changed files
with
123 additions
and
21 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,46 @@ | ||
<script setup lang="ts"> | ||
import type { PropType } from 'vue'; | ||
defineProps({ | ||
html: { | ||
type: String, | ||
required: true, | ||
}, | ||
color: { | ||
type: String, | ||
required: false, | ||
}, | ||
background: { | ||
type: String, | ||
required: false, | ||
}, | ||
style: { | ||
type: Object as PropType<Record<string, string>>, | ||
required: false, | ||
}, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<span | ||
class="html-text" | ||
:style="{ | ||
'--mark-color-text': color, | ||
'--mark-color-background': background, | ||
...style, | ||
}" | ||
v-html="html" | ||
> | ||
</span> | ||
</template> | ||
|
||
<style scoped lang="scss"> | ||
.html-text { | ||
white-space: pre-wrap; | ||
:deep(mark) { | ||
color: var(--mark-color-text, var(--color-primary-lighter)); | ||
background-color: var(--mark-color-background, none); | ||
} | ||
} | ||
</style> |
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 +1,29 @@ | ||
import UFuzzy from '@leeoniya/ufuzzy'; | ||
|
||
export const isTrailer = (title: string) => title && /(trailer|teaser)/.test(title.toLowerCase()); | ||
|
||
let fuzzy: UFuzzy; | ||
export const fuzzyMatch = ( | ||
values: string[], | ||
search: string, | ||
): { | ||
match: string[]; | ||
highlight: string[]; | ||
ids: { exact?: number; matches: number[]; order: number[]; info: { idx: number[]; ranges: number[][] } }; | ||
} => { | ||
if (!fuzzy) fuzzy = new UFuzzy(); | ||
const matches = fuzzy.filter(values, search); | ||
if (matches === null || !matches.length) return { match: [], highlight: [], ids: { matches: [], order: [], info: { idx: [], ranges: [] } } }; | ||
|
||
const info = fuzzy.info(matches, values, search); | ||
const order = fuzzy.sort(info, values, search); | ||
const match: string[] = order.map(idx => values[matches[idx]]); | ||
const highlight: string[] = order.map(idx => UFuzzy.highlight(values[info.idx[idx]], info.ranges[idx])); | ||
|
||
const exact = match.findIndex(m => m === search); | ||
if (exact !== -1) { | ||
match.splice(exact, 1); | ||
highlight.splice(exact, 1); | ||
} | ||
return { match, highlight, ids: { exact, matches, order, info } }; | ||
}; |