Michal Srb
Michal Srb2mo ago

Text Search is hard to use

Two pieces of feedback: 1. The docs don't teach useStableValue or (less good imo) useStableQuery, don't link to https://stack.convex.dev/help-my-app-is-overreacting (which is long though), so creating a search interface is not straightforward without results flickering. 2. Now that search changed from prefix to fuzzy, it no longer fits super well the use case of looking up people by name (or room by name etc.), because irrelevant results are still returned. This could be alleviated (even if it's not the ideal fix) if the docs gave a recipe for computing the relevance score on the client side (or some measures resembling the relevance score).
Help, my app is overreacting!
Reactive backends like Convex make building live-updating apps a cinch, but default behavior might be too reactive for some use cases. Not to worry! L...
5 Replies
Convex Bot
Convex Bot2mo ago
jamwt
jamwt2mo ago
you just need to git good with convex good feedback, thanks @Michal Srb ❤️
ampp
ampp2mo ago
Now i'm super curious where i can find useStableValue at.. 😅
Michal Srb
Michal SrbOP2mo ago
Perhaps better called useStaleValue
function useStableValue<T>(value: T) {
const ref = useRef(value);
if (value !== undefined) {
ref.current = value;
}
return { value: ref.current, isStale: value === undefined };
}
function useStableValue<T>(value: T) {
const ref = useRef(value);
if (value !== undefined) {
ref.current = value;
}
return { value: ref.current, isStale: value === undefined };
}
And here it is with a reset option, but that's kinda getting specific to the use-case scenario:
function useStableValue<T>(value: T, options: { reset: boolean }) {
const ref = useRef(value);
if (value !== undefined || options.reset) {
ref.current = value;
}
return { value: ref.current, isStale: value === undefined };
}
function useStableValue<T>(value: T, options: { reset: boolean }) {
const ref = useRef(value);
if (value !== undefined || options.reset) {
ref.current = value;
}
return { value: ref.current, isStale: value === undefined };
}
Michal Srb
Michal SrbOP2mo ago
I was wrong on the second point - for the use cases I listed text search works great. What I am doing again, which I've done in the past, is removing diacritics in data and the needle like this: https://stackoverflow.com/a/37511463/1526986 That might be worth linking from Text Search docs as a recipe (with explanation of the indexing side).
Stack Overflow
Remove accents/diacritics in a string in JavaScript
How do I remove accentuated characters from a string? Especially in IE6, I had something like this: accentsTidy = function(s){ var r=s.toLowerCase(); r = r.replace(new RegExp(/\s/g),""); ...