medic / lucene-query-generator

Generate escaped lucene query strings
Apache License 2.0
16 stars 7 forks source link

OR not escaped #4

Open ebbersjathomes opened 9 years ago

ebbersjathomes commented 9 years ago
var generator = require('lucene-query-generator');

console.log(generator.convert({
    $operands: [
        { state: 'OR' }
    ]
}));

//state:OR
ghost commented 9 years ago

Thanks for the report, we'll look in to it as soon as possible.

garethbowen commented 9 years ago

Confirmed the above generates an invalid lucene query.

This is currently by design because we want advanced users to be able to enter valid lucene queries.

@joeandaverde submitted a PR that never quite got merged for a similar issue regarding email address tokenization.

I propose we start always escaping strings because that seems to be the expected behaviour, and introduce a new schema type called "lucene" (or something better) for passing lucene query snippets. For example:

var generator = require('lucene-query-generator');

console.log(generator.convert({
  $operands: [
    { state: 'OR' }
  ]
}));

//state:"OR"

console.log(generator.convert({
  $operands: [
    { state: 'OR' }
  ]
}, {
  schema: {
    state: 'lucene'
  }
}));
//state:OR (which errors in lucene as expected)

@ebbersjathomes Does that make sense to you?

ghost commented 9 years ago

Proposal supported on my end; +1.