cal.com icon indicating copy to clipboard operation
cal.com copied to clipboard

[CAL-1629] Fuzzy matching while searching

Open Udit-takkar opened this issue 2 years ago • 2 comments

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

Udit-takkar avatar May 08 '23 11:05 Udit-takkar

Hi @Udit-takkar Can I solve this issue? There can be 2 approaches to solving this issue:

  1. 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.

  1. 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.

SohamRatnaparkhi avatar May 08 '23 12:05 SohamRatnaparkhi

Hey @Udit-takkar please assign this issue to @SohamRatnaparkhi So that he can start working on it. Thanks

pranjalg13 avatar May 09 '23 16:05 pranjalg13

hey @SohamRatnaparkhi @pranjalg13 i think @G3root is working on this

Udit-takkar avatar May 09 '23 18:05 Udit-takkar