Make the ChildrenQuery and ParentQuery not rely on the fact that score of 0 means that there isn't a match.

This commit is contained in:
Martijn van Groningen 2013-12-01 17:22:58 +01:00
parent 1285894f5f
commit 04675f85cf
2 changed files with 23 additions and 16 deletions

View File

@ -54,7 +54,6 @@ import java.util.Set;
* all parent documents having the same uid value that is collected in the first phase are emitted as hit including
* a score based on the aggregated child scores and score type.
*/
// TODO We use a score of 0 to indicate a doc was not scored in uidToScore, this means score of 0 can be problematic, if we move to HPCC, we can use lset/...
public class ChildrenQuery extends Query {
private final String parentType;
@ -292,7 +291,9 @@ public class ChildrenQuery extends Query {
HashedBytesArray uid = idTypeCache.idByDoc(currentDocId);
currentScore = uidToScore.get(uid);
if (currentScore != 0) {
if (uidToScore.containsKey(uid)) {
// Can use lget b/c uidToScore is only used by one thread at the time (via CacheRecycler)
currentScore = uidToScore.lget();
remaining--;
return currentDocId;
}
@ -312,8 +313,9 @@ public class ChildrenQuery extends Query {
}
HashedBytesArray uid = idTypeCache.idByDoc(currentDocId);
currentScore = uidToScore.get(uid);
if (currentScore != 0) {
if (uidToScore.containsKey(uid)) {
// Can use lget b/c uidToScore is only used by one thread at the time (via CacheRecycler)
currentScore = uidToScore.lget();
remaining--;
return currentDocId;
} else {
@ -350,10 +352,11 @@ public class ChildrenQuery extends Query {
}
HashedBytesArray uid = idTypeCache.idByDoc(currentDocId);
currentScore = uidToScore.get(uid);
if (currentScore != 0) {
remaining--;
if (uidToScore.containsKey(uid)) {
// Can use lget b/c uidToScore is only used by one thread at the time (via CacheRecycler)
currentScore = uidToScore.lget();
currentScore /= uidToCount.get(uid);
remaining--;
return currentDocId;
}
}
@ -372,10 +375,11 @@ public class ChildrenQuery extends Query {
}
HashedBytesArray uid = idTypeCache.idByDoc(currentDocId);
currentScore = uidToScore.get(uid);
if (currentScore != 0) {
remaining--;
if (uidToScore.containsKey(uid)) {
// Can use lget b/c uidToScore is only used by one thread at the time (via CacheRecycler)
currentScore = uidToScore.lget();
currentScore /= uidToCount.get(uid);
remaining--;
return currentDocId;
} else {
return nextDoc();

View File

@ -46,7 +46,6 @@ import java.util.Set;
* connects the matching parent docs to the related child documents
* using the {@link IdReaderTypeCache}.
*/
// TODO We use a score of 0 to indicate a doc was not scored in uidToScore, this means score of 0 can be problematic, if we move to HPCC, we can use lset/...
public class ParentQuery extends Query {
private final Query originalParentQuery;
@ -278,8 +277,9 @@ public class ParentQuery extends Query {
if (uid == null) {
continue;
}
currentScore = uidToScore.get(uid);
if (currentScore != 0) {
if (uidToScore.containsKey(uid)) {
// Can use lget b/c uidToScore is only used by one thread at the time (via CacheRecycler)
currentScore = uidToScore.lget();
return currentChildDoc;
}
}
@ -295,11 +295,14 @@ public class ParentQuery extends Query {
if (uid == null) {
return nextDoc();
}
currentScore = uidToScore.get(uid);
if (currentScore == 0) {
if (uidToScore.containsKey(uid)) {
// Can use lget b/c uidToScore is only used by one thread at the time (via CacheRecycler)
currentScore = uidToScore.lget();
return currentChildDoc;
} else {
return nextDoc();
}
return currentChildDoc;
}
@Override