Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to return an exact match when there are two words to search for? #206

Closed
http91 opened this issue Nov 11, 2017 · 1 comment
Closed
Labels

Comments

@http91
Copy link

http91 commented Nov 11, 2017

Hi.

Here's what I'm trying to accomplish.

Old War shouldn't match, but it does. -> It's not what I'm looking for, there must be an exact match, even though there are two words. "Old Man" is a yes, but "Old War" is a no.
Man's War should match. It does at this moment.
Silmarillion should match. It does at this moment.
The Silmarillion should also match. It does at this moment.

var express = require('express');
var router = express.Router();
var path = require("path");
var async1 = require("async");
var Fuse = require("fuse.js");

var options = {
  shouldSort: true,
  tokenize: true,
  matchAllTokens: true,
  findAllMatches: true,
  threshold: 0,
  location: 0,
  distance: 0,
  maxPatternLength: 32,
  minMatchCharLength: 2,
  keys: ["title"]
};

Code

var arr = [
  {
    title: "Old Man's War",
    author: {
      firstName: "John",
      lastName: "Scalzi"
    }
  }, 
  {
    title: "The SilmarillionADDITIONALTEXT",
    author: {
      firstName: "J.R.R",
      lastName: "Tolkien"
    }
  }
];

var keywords = ["Old War", "random title"];

router.get('/search', function (req, res, next) {

  async1.waterfall([
    function (callback) {
      var fuse = new Fuse(r, options);

      async1.map(keywords, function (keyword, asyncCallback) {
        var results = fuse.search(keyword);

        if (results.length !== 0) {
          async1.map(results, function (result, async2Callback) {
            console.log(result.title + " " + keyword);
          });
        }
      });
      callback(null, 'done!');
    }
  ], function (err, result) {
    res.sendStatus(200);
  });

});

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant