olivernn / lunr.js

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

same Clause (term) multiple times #311

Open drzraf opened 7 years ago

drzraf commented 7 years ago

Please document what is expected to happens with following q.term(t); q.term(t, { field: ["foo"] }); and, in opposite order: q.term(t, { field: ["foo"] }); q.term(t);

olivernn commented 7 years ago

What do you expect to happen in those cases?

With the current implementation a term that is repeated will have a higher weight in the query, i.e. it will be similar to providing a boost of 2 (if the term appears twice in the query).

How Lunr handles these cases is not documented because I think it's an implementation detail rather than a specific property of the interface. As soon as its documented its harder to change, which might hinder any optimisations that could be applied. That said, if there is a solid reason for consumers to know this behaviour then its something that could be documented.

drzraf commented 7 years ago

In my implementation I'm trying to setup a general AND search

When I process each term of the query, I want to maximize the probability to find it. Thus searching this term in multiple indexes with various boost/fields settings should "extend" the search surface and not "reduce" it. So q.term(t); q.term(t, { field: ["foo"] }); should keep search t in * fields and not only foo.

That being said, there may exist other contexts where, like in a RDBMS query-builder, changing a where-clause for a given field would reset it.