[CAL-1629] Fuzzy matching while searching
Is your proposal related to a problem?
we have been implementing search functionality here https://github.com/calcom/cal.com/pull/8742 and https://github.com/calcom/cal.com/pull/8659/files.
It would be much better experience if we support fuzzy searching which would give us similar results related to search query so that we see relevant result even when we misspell something
Might be relevant https://github.com/prisma/prisma/issues/7986
or we can also look into Full text seach feature in prisma https://www.prisma.io/dataguide/managing-databases/intro-to-full-text-search
Hi @Udit-takkar Can I solve this issue? There can be 2 approaches to solving this issue:
- Using fuse.js (link) package which has fuzzy matching options Then, the code to filter the results in team-members-view.tsx roughly would look something as follows:
import Fuse from 'fuse.js';
const { team } = props;
const { t } = useLocale();
const [query, setQuery] = useState<string>("");
const members = team?.members;
const options = {
keys: ['email', 'username', 'name'],
threshold: 0.4, // adjust this to control the fuzziness of the search
};
const fuse = members ? new Fuse(members, options) : null;
const membersList = fuse ? fuse.search(query).map(result => result.item) : members;
const checkIfExist = (comp: string, query: string) =>
comp.toLowerCase().replace(/\s+/g, "").includes(query.toLowerCase().replace(/\s+/g, ""));
This won't be the exact code as I have just written the important parts of the code here.
- If we want to avoid using third party fuse.js, then we can write our own distance function algorithm, which calculates the minimum number of edits (insertions, deletions, or substitutions) required to transform one string into another. In this case, we can use it to calculate the similarity between the search query and each member's name, email, and username. It's somewhat of a dynamic programming approach.
Hey @Udit-takkar please assign this issue to @SohamRatnaparkhi So that he can start working on it. Thanks
hey @SohamRatnaparkhi @pranjalg13 i think @G3root is working on this