don't return any id when doesn't exists

This commit is contained in:
kimchy 2011-04-17 06:21:39 +03:00
parent fb35b1c993
commit efb3e97ce4
3 changed files with 4 additions and 4 deletions

View File

@ -248,8 +248,8 @@ public class TransportGetAction extends TransportShardSingleOperationAction<GetR
continue; continue;
} }
UidField.DocIdAndVersion docIdAndVersion = UidField.loadDocIdAndVersion(reader, uid); UidField.DocIdAndVersion docIdAndVersion = UidField.loadDocIdAndVersion(reader, uid);
// either -2 (its there, but no version associated), or an actual version // not null if it exists
if (docIdAndVersion.docId != -1) { if (docIdAndVersion != null) {
return docIdAndVersion; return docIdAndVersion;
} }
} }

View File

@ -58,7 +58,7 @@ public class UidField extends AbstractField {
try { try {
uid = reader.termPositions(term); uid = reader.termPositions(term);
if (!uid.next()) { if (!uid.next()) {
return new DocIdAndVersion(Lucene.NO_DOC, -1, reader); return null; // no doc
} }
docId = uid.doc(); docId = uid.doc();
uid.nextPosition(); uid.nextPosition();

View File

@ -67,6 +67,6 @@ public class UidFieldTests {
writer.deleteDocuments(new Term("_uid", "1")); writer.deleteDocuments(new Term("_uid", "1"));
reader = reader.reopen(); reader = reader.reopen();
assertThat(UidField.loadVersion(reader, new Term("_uid", "1")), equalTo(-1l)); assertThat(UidField.loadVersion(reader, new Term("_uid", "1")), equalTo(-1l));
assertThat(UidField.loadDocIdAndVersion(reader, new Term("_uid", "1")).version, equalTo(-1l)); assertThat(UidField.loadDocIdAndVersion(reader, new Term("_uid", "1")), nullValue());
} }
} }