Details

Description

In some situations it would be useful to have a Filter that simply returns all document that either have at least one or no value in a certain field. We don't have something like that out of the box and adding it seems straight forward.

I will open new issue and fix the TODO, especially as I dont know if trunk really likes e.g. on FieldCacheTermsFilter that getOrd() is called with doc id out of range... Maybe it throws AIOOBE, but thats ugly.

Uwe Schindler
added a comment - 24/Nov/11 23:22 +1 looks fine. Cool heavy fast ping-pong
I will open new issue and fix the TODO, especially as I dont know if trunk really likes e.g. on FieldCacheTermsFilter that getOrd() is called with doc id out of range... Maybe it throws AIOOBE, but thats ugly.

next iteration. I added a AIOOBE to all the match methods to make the interface happy. I think we should fix this as uwe mentioned. Uwe, can you create a subtask / issue to fix this.. I think you already on it no? I added some more optimizations if the Bits is instanceof MatchNoBits / MatchAllBits respectively I return null instead of the DocIdSetIterator when appropriate. all test pass..

Simon Willnauer
added a comment - 24/Nov/11 23:18 next iteration. I added a AIOOBE to all the match methods to make the interface happy. I think we should fix this as uwe mentioned. Uwe, can you create a subtask / issue to fix this.. I think you already on it no? I added some more optimizations if the Bits is instanceof MatchNoBits / MatchAllBits respectively I return null instead of the DocIdSetIterator when appropriate. all test pass..
I think it's ready..

Patch looks good, except the AIOOBE requirement - which is a broken API. I will fix this now by always doing (doc < maxDoc) check in the iterator and also factor out the abstract class from FCRF. Also 3.x has a bug in FCRF with respecting deletions (I already discussed with Mike several weeks ago).

Uwe Schindler
added a comment - 24/Nov/11 23:05 Patch looks good, except the AIOOBE requirement - which is a broken API. I will fix this now by always doing (doc < maxDoc) check in the iterator and also factor out the abstract class from FCRF. Also 3.x has a bug in FCRF with respecting deletions (I already discussed with Mike several weeks ago).

guys thanks for the comments! I incorporated uwes shortcut and fixed the name to FieldValueFilter. I extened the testcase to also use deletions. Uwe, whatever you want to do feel free to upload a new patch. I already added a changes.txt entry for this too...

Simon Willnauer
added a comment - 24/Nov/11 22:55 guys thanks for the comments! I incorporated uwes shortcut and fixed the name to FieldValueFilter. I extened the testcase to also use deletions. Uwe, whatever you want to do feel free to upload a new patch. I already added a changes.txt entry for this too...

Robert: I already said that. The Filter could also live of the shortcuts, if getDocsWithField returns MatchAllBits it could shortcut to MatchAllDocsQuery/Filter or return null (depending on negation or not). In all cases this Filter could in all cases do some shortcuts

I will provide a patch later adressing also the stupid "rely on ArrayIndexOutOfBoundsException". I am not even sure that FieldCacheTermsFilter works correct in trunk... I would prefer to add the "< maxDoc" check in the iterator impl beyond FieldCacheDocIdSet.

Uwe Schindler
added a comment - 24/Nov/11 22:34 Robert: I already said that. The Filter could also live of the shortcuts, if getDocsWithField returns MatchAllBits it could shortcut to MatchAllDocsQuery/Filter or return null (depending on negation or not). In all cases this Filter could in all cases do some shortcuts
I will provide a patch later adressing also the stupid "rely on ArrayIndexOutOfBoundsException". I am not even sure that FieldCacheTermsFilter works correct in trunk... I would prefer to add the "< maxDoc" check in the iterator impl beyond FieldCacheDocIdSet.

Robert Muir
added a comment - 24/Nov/11 22:30 Hello,
I think rather than having NoFieldValueFilter with boolean negate, we should instead use a positive name for the filter, to avoid requiring double negations.
So the name would something positive like FieldValueFilter instead.

the first patch looks exactly like I said in our first ideas-exchange!

There are smaller problems (but solveable) and one optimization... (a trick one...): FieldCacheDocIdSet has some special cases which work with the implementation here, but are unclean and should violate some assertions - and should be fixed...:

FieldCacheDocIdSet excepts that the match() method throws ArrayIndexOutOfBoundsException when the FieldCacheArray is out of bounds. With the FixedBitSet behind that implementation of the FieldCache this basically works, but should violate some code assertions added by MikeMcCandless (not sure why the testcase does not hit this - doesn't it - I assume it does not because the trunk bits() on DocIdSet will intercept this as our filter is not sparse -> it switches to random access)

The FieldCacheDocIdSet should maybe made un-private and refactored out of the FieldCacheRangeFilter.

The positive case could be optimized: A instanceof check in the getDocIdSet() method could check for the positive case that the FieldCacheImpl itsself returns a FixedBitSet/DocIdSet already and return this directly:

In general the other cases can be easily done by the default stupid (stupid in the case that its slowly iterating by doc++ and in trunk directly uses the Bits) impl like you did, but once factoring out the FieldCacheRangeFilter.FieldCacheDocIdSet we could optimize this and maybe have a better negation.

In all cases I dont like double negation of this Filter.

I'll work on the problems and make this filter work better. Should I take this issue and solve the problems first? I also want to backport the FieldCacheTermsFilter code-duplication removal in trunk to 3.x, so some cleanup is really needed!

Uwe Schindler
added a comment - 24/Nov/11 22:22 Hi Simon,
the first patch looks exactly like I said in our first ideas-exchange!
There are smaller problems (but solveable) and one optimization... (a trick one...): FieldCacheDocIdSet has some special cases which work with the implementation here, but are unclean and should violate some assertions - and should be fixed...:
FieldCacheDocIdSet excepts that the match() method throws ArrayIndexOutOfBoundsException when the FieldCacheArray is out of bounds. With the FixedBitSet behind that implementation of the FieldCache this basically works, but should violate some code assertions added by MikeMcCandless (not sure why the testcase does not hit this - doesn't it - I assume it does not because the trunk bits() on DocIdSet will intercept this as our filter is not sparse -> it switches to random access)
The FieldCacheDocIdSet should maybe made un-private and refactored out of the FieldCacheRangeFilter.
The positive case could be optimized: A instanceof check in the getDocIdSet() method could check for the positive case that the FieldCacheImpl itsself returns a FixedBitSet/DocIdSet already and return this directly:
final Bits docsWithField = FieldCache.DEFAULT.getDocsWithField(context.reader, field);
if (negate && docsWithField instanceof DocIdSet) // this is always the case for our current impl - but who knows :-)
return (DocIdSet) docsWithField;
In general the other cases can be easily done by the default stupid (stupid in the case that its slowly iterating by doc++ and in trunk directly uses the Bits) impl like you did, but once factoring out the FieldCacheRangeFilter.FieldCacheDocIdSet we could optimize this and maybe have a better negation.
In all cases I dont like double negation of this Filter.
I'll work on the problems and make this filter work better. Should I take this issue and solve the problems first? I also want to backport the FieldCacheTermsFilter code-duplication removal in trunk to 3.x, so some cleanup is really needed!
I will come with a patch adressing those problems later or tomorrow.

here is an initial patch. maybe somebody more familiar with our new filter hierarchy etc. can review this. There is still a nocommit in there since I am not sure if that is the best way of doing this. Uwe had some ideas I think..

Simon Willnauer
added a comment - 24/Nov/11 21:50 here is an initial patch. maybe somebody more familiar with our new filter hierarchy etc. can review this. There is still a nocommit in there since I am not sure if that is the best way of doing this. Uwe had some ideas I think..