olivernn / lunr.js

A bit like Solr, but much smaller and not as bright
http://lunrjs.com
MIT License
8.87k stars 546 forks source link

Querying with field scope tokens on array type fields returns no results #483

Open RShohoney opened 3 years ago

RShohoney commented 3 years ago

I have an index where one field is stored as array of strings. Those strings will contain multiple tokens. When I query that field by using a generated query, I get no results. An example of the behavior is as such.

const objs = [
  { 
      myField: ['this is a car', 'this is also a car']
  },
  {
     myField: ['boat']
  }
];

const index = lunr(function () { 
  this.field('myField');

  objs.forEach(function (doc) {
    this.add(doc)
  }, this);
});

index.search('+myField:car'); // 0 results
index.search('+myField:boat'); // 1 result

My understanding of the documentation is that the query will be executed against the result of .toString() of each element in an array, when an array is present. Given that understanding, I'd expect `index.search('+myField:string') to return 2 results.

Let me know if you need more information, or if I'm misunderstanding the docs.