Reputation: 43
I have lucene document like this
id age status 1 1 2 C G 2 2 G 3 2 1 C G 4 2 5 C H
I did search like
age: 2 AND status: 'G'
It returned the first three document.
The problem is I did not want the third document with id:3. I only wanted the first two result. The data is arranged like this:
for id 1:
age 1 has status C
age 2 has status G
for id 3:
age 2 has status C
age 1 has status G
and I wanted age 2 with status G not C.. This is why id 3 is wrong for me.
how do I achieve this? I am using java
Upvotes: 0
Views: 56
Reputation: 5693
For searches where 2+ attributes are bound together (like id 3 with age=2/status=C and age=1/status=G above), I think you need to bind them together in the index -- for example, adding a separate Lucene field age_status, so your Lucene documents would look like:
id age status age_status
1 1 2 C G 1/C, 2/G
2 2 G 2/G
3 2 1 C G 2/C, 1/G
4 2 5 C H 2/C, 5/H
(where '/' is the separator for age and status in age_status and 2+ values in age_status are shown with delimiting commas). This would let you search on age_status:2/G
, yielding only Lucene documents id=1 and id=2 as search hits.
Upvotes: 1