How to use the talisman/metrics/distance/jaccard.similarity function in talisman

To help you get started, we’ve selected a few talisman examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Icemic / search.bakery.moe / server / routes / search.js View on Github external
const results = await Anime.find({
    keywords: { $in: cutString },
    // $or: [
    //   { title: /searchString/ },
    //   { keywords: { $in: cutString } }
    // ]
  });

  const list = [];
  for (const record of results) {
    const cutAlias = record.keywords;
    let total = [...new Set([...cutAlias, ...cutString])].length;

    let maxDistance = 0;
    for (const alias of record.alias) {
      maxDistance = Math.max(maxDistance, jsimilarity(searchString, alias))
      // console.log(searchString, alias, maxDistance)
    }

    list.push([maxDistance * (cutString.length + cutAlias.length - total), record.title, record._id, record.bgmid]);
  }

  let ended = false;
  let ending = page * 10;

  if (list.length < (page - 1) * 10) {
    ended = true;
    ctx.body = { items: [], ended };
    return;
  } else if (list.length <= ending) {
    ended = true;
    ending = list.length;