Boris Callens
Boris Callens

Reputation: 93407

Lucene query to exclude docs, but not docs with partial matches

Say I have a set of docs that go like this:

Is there a way to create a query that will filter out the mercedes, but not the mercedes trucks?

Upvotes: 0

Views: 726

Answers (2)

dustyburwell
dustyburwell

Reputation: 5813

If you need the phrase "mercedes trucks" then your query can just be

"mercedes trucks"

if you need the words mercedes and trucks then your query can be

+mercedes +trucks

OR

mercedes AND trucks

These queries will naturally filter out the docs that don't contain the word trucks.

Edit: Unless this is a keyword/untokenized field. In that case only the first example will work.

Upvotes: 1

Razzie
Razzie

Reputation: 31232

Have you tried:

+carbrand:mercedes* -carbrand:mercedes

(or whatever the fieldname is of course). Or am I oversimplifying based on the specific example?

Upvotes: 0

Related Questions