tags:

views:

329

answers:

2

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

  • mercedes
  • mercedes trucks

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

A: 

Have you tried:

+carbrand:mercedes* -carbrand:mercedes

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

Razzie
as soon as I add -carbrand:mercedes nothing returns. I didn't tokenize the field because I need the spaces to be there.
borisCallens
ok, I'd tokenize the field then. Not sure why that wouldn't be possible? Can't think of another solution to be honest.
Razzie
+1  A: 

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.

dustyburwell
I need two results: "mercedes" and "mercedes trucks" to return. So they are untokenized (I need the spaces).
borisCallens
Are you saying you need the spaces in the field returned in the document from Lucene? If you tokeninze the field and store it in lucene it will still return the value with the spaces.
dustyburwell