mirror of https://github.com/apache/lucene.git
LUCENE-5675: add docs/AndPositionsEnums
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5675@1594985 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a301ab5610
commit
60aa1ae3fb
|
@ -61,14 +61,31 @@ public final class IDVersionPostingsReader extends PostingsReaderBase {
|
|||
|
||||
@Override
|
||||
public DocsEnum docs(FieldInfo fieldInfo, BlockTermState termState, Bits liveDocs, DocsEnum reuse, int flags) throws IOException {
|
||||
// nocommit todo -- need a SingleDocDocsEnum
|
||||
return null;
|
||||
SingleDocsEnum docsEnum;
|
||||
|
||||
if (reuse instanceof SingleDocsEnum) {
|
||||
docsEnum = (SingleDocsEnum) reuse;
|
||||
} else {
|
||||
docsEnum = new SingleDocsEnum();
|
||||
}
|
||||
docsEnum.reset(((IDVersionTermState) termState).docID, liveDocs);
|
||||
|
||||
return docsEnum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocsAndPositionsEnum docsAndPositions(FieldInfo fieldInfo, BlockTermState termState, Bits liveDocs,
|
||||
public DocsAndPositionsEnum docsAndPositions(FieldInfo fieldInfo, BlockTermState _termState, Bits liveDocs,
|
||||
DocsAndPositionsEnum reuse, int flags) {
|
||||
return null;
|
||||
SingleDocsAndPositionsEnum posEnum;
|
||||
|
||||
if (reuse instanceof SingleDocsAndPositionsEnum) {
|
||||
posEnum = (SingleDocsAndPositionsEnum) reuse;
|
||||
} else {
|
||||
posEnum = new SingleDocsAndPositionsEnum();
|
||||
}
|
||||
IDVersionTermState termState = (IDVersionTermState) _termState;
|
||||
posEnum.reset(termState.docID, termState.idVersion, liveDocs);
|
||||
return posEnum;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
package org.apache.lucene.codecs.idversion;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.index.DocsAndPositionsEnum;
|
||||
import org.apache.lucene.util.Bits;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
|
||||
class SingleDocsAndPositionsEnum extends DocsAndPositionsEnum {
|
||||
private int doc;
|
||||
private int pos;
|
||||
private int singleDocID;
|
||||
private Bits liveDocs;
|
||||
private long version;
|
||||
private final BytesRef payload = new BytesRef();
|
||||
|
||||
/** For reuse */
|
||||
public void reset(int singleDocID, long version, Bits liveDocs) {
|
||||
doc = -1;
|
||||
this.liveDocs = liveDocs;
|
||||
this.singleDocID = singleDocID;
|
||||
this.version = version;
|
||||
pos = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextDoc() {
|
||||
if (doc == -1 && (liveDocs == null || liveDocs.get(singleDocID))) {
|
||||
doc = singleDocID;
|
||||
} else {
|
||||
doc = NO_MORE_DOCS;
|
||||
}
|
||||
pos = 0;
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int advance(int target) {
|
||||
if (doc == -1 && target <= singleDocID && (liveDocs == null || liveDocs.get(singleDocID))) {
|
||||
doc = singleDocID;
|
||||
} else {
|
||||
doc = NO_MORE_DOCS;
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long cost() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextPosition() {
|
||||
assert pos == -1;
|
||||
pos = 0;
|
||||
// nocommit re-encode version back into payload here:
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytesRef getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int startOffset() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int endOffset() {
|
||||
return -1;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package org.apache.lucene.codecs.idversion;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.index.DocsEnum;
|
||||
import org.apache.lucene.util.Bits;
|
||||
|
||||
class SingleDocsEnum extends DocsEnum {
|
||||
|
||||
private int doc;
|
||||
private int singleDocID;
|
||||
private Bits liveDocs;
|
||||
|
||||
/** For reuse */
|
||||
public void reset(int singleDocID, Bits liveDocs) {
|
||||
doc = -1;
|
||||
this.liveDocs = liveDocs;
|
||||
this.singleDocID = singleDocID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextDoc() {
|
||||
if (doc == -1 && (liveDocs == null || liveDocs.get(singleDocID))) {
|
||||
doc = singleDocID;
|
||||
} else {
|
||||
doc = NO_MORE_DOCS;
|
||||
}
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int advance(int target) {
|
||||
if (doc == -1 && target <= singleDocID && (liveDocs == null || liveDocs.get(singleDocID))) {
|
||||
doc = singleDocID;
|
||||
} else {
|
||||
doc = NO_MORE_DOCS;
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long cost() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() {
|
||||
return 1;
|
||||
}
|
||||
}
|
|
@ -22,3 +22,4 @@ org.apache.lucene.codecs.memory.FSTPulsing41PostingsFormat
|
|||
org.apache.lucene.codecs.memory.FSTOrdPulsing41PostingsFormat
|
||||
org.apache.lucene.codecs.memory.FSTPostingsFormat
|
||||
org.apache.lucene.codecs.memory.FSTOrdPostingsFormat
|
||||
org.apache.lucene.codecs.idversion.IDVersionPostingsFormat
|
||||
|
|
|
@ -1318,6 +1318,8 @@ public class BlockTreeTermsReader extends FieldsProducer {
|
|||
private Frame currentFrame;
|
||||
private boolean termExists;
|
||||
|
||||
// nocommit make this public "for casting" and add a getVersion method?
|
||||
|
||||
private int targetBeforeCurrentLength;
|
||||
|
||||
private final ByteArrayDataInput scratchReader = new ByteArrayDataInput();
|
||||
|
@ -1560,6 +1562,8 @@ public class BlockTreeTermsReader extends FieldsProducer {
|
|||
return true;
|
||||
}
|
||||
|
||||
// nocommit we need a seekExact(BytesRef target, long minVersion) API?
|
||||
|
||||
@Override
|
||||
public boolean seekExact(final BytesRef target) throws IOException {
|
||||
|
||||
|
|
Loading…
Reference in New Issue