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

NOT operator #76

Open
paulcanning opened this issue Jun 1, 2022 · 2 comments
Open

NOT operator #76

paulcanning opened this issue Jun 1, 2022 · 2 comments

Comments

@paulcanning
Copy link
Contributor

Trying to figure out how to implement the NOT operator, using the same style of the others.

module.exports = (l, r) => (data) => {
  let rl = l(data);
  let rr = r(data);
  let rla = Math.abs(rl);
  let rra = Math.abs(rr);
  return rla !== rra;
};

This is giving me promising results, eg

console.log(data.filter(lucene('species:human NOT description:master')));

[
  {
    name: 'Anakin Skywalker',
    description: 'Fallen Jedi, the chosen one.',
    species: 'Human'
  }
]

But then flops with something like

console.log(data.filter(lucene('species:human NOT name:o')));

// should be
[
  {
    name: 'Anakin Skywalker',
    description: 'Fallen Jedi, the chosen one.',
    species: 'Human'
  }
]

// actual result
[
  { name: 'C-3PO', description: 'Protocol droid.', species: 'Droid' },
  {
    name: 'Anakin Skywalker',
    description: 'Fallen Jedi, the chosen one.',
    species: 'Human'
  },
  {
    name: 'Moon Moon',
    description: 'Mentally challenged wolf.',
    species: 'Wolf'
  }
]

No idea how it's so broken, but like I mentioned in another issue, I don't really understand the logic used in the operators yet. This is just a first stab in the dark at the NOT operator.

@finwo
Copy link
Owner

finwo commented Jun 1, 2022

The original idea of the NOT operator was that it'd revert the result of the matcher, basically subtracting points from the end-result if the matcher reports it's matching.

There's a high chance I have not implemented that basic idea properly though

@paulcanning
Copy link
Contributor Author

Bit more fiddling, and this seems to give better results

module.exports = (l, r) => (data) => {
  let rl = l(data);
  let rr = r(data);

  if (rl > rr) {
    return rl;
  }

  return 0;
};

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

No branches or pull requests

2 participants