mirror of https://github.com/apache/lucene.git
fix nocommits
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4765@1445478 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
73d9834a5b
commit
887c3a2d72
|
@ -0,0 +1,64 @@
|
||||||
|
package org.apache.lucene.index;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.util.BytesRef;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exposes multi-valued view over a single-valued instance.
|
||||||
|
* <p>
|
||||||
|
* This can be used if you want to have one multi-valued implementation
|
||||||
|
* against e.g. FieldCache.getDocTermOrds that also works for single-valued
|
||||||
|
* fields.
|
||||||
|
*/
|
||||||
|
public class SingletonSortedSetDocValues extends SortedSetDocValues {
|
||||||
|
private final SortedDocValues in;
|
||||||
|
private int docID;
|
||||||
|
|
||||||
|
/** Creates a multi-valued view over the provided SortedDocValues */
|
||||||
|
public SingletonSortedSetDocValues(SortedDocValues in) {
|
||||||
|
this.in = in;
|
||||||
|
assert NO_MORE_ORDS == -1; // this allows our nextOrd() to work for missing values without a check
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long nextOrd() {
|
||||||
|
return in.getOrd(docID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDocument(int docID) {
|
||||||
|
this.docID = docID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lookupOrd(long ord, BytesRef result) {
|
||||||
|
// cast is ok: single-valued cannot exceed Integer.MAX_VALUE
|
||||||
|
in.lookupOrd((int)ord, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getValueCount() {
|
||||||
|
return in.getValueCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long lookupTerm(BytesRef key) {
|
||||||
|
return in.lookupTerm(key);
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,7 +33,7 @@ public abstract class SortedSetDocValues {
|
||||||
* constructors, typically implicit.) */
|
* constructors, typically implicit.) */
|
||||||
protected SortedSetDocValues() {}
|
protected SortedSetDocValues() {}
|
||||||
|
|
||||||
public static final long NO_MORE_ORDS = Long.MAX_VALUE;
|
public static final long NO_MORE_ORDS = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next ordinal for the current document (previously
|
* Returns the next ordinal for the current document (previously
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.apache.lucene.index.FieldInfo;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.NumericDocValues;
|
import org.apache.lucene.index.NumericDocValues;
|
||||||
import org.apache.lucene.index.SegmentReader;
|
import org.apache.lucene.index.SegmentReader;
|
||||||
|
import org.apache.lucene.index.SingletonSortedSetDocValues;
|
||||||
import org.apache.lucene.index.SortedDocValues;
|
import org.apache.lucene.index.SortedDocValues;
|
||||||
import org.apache.lucene.index.SortedSetDocValues;
|
import org.apache.lucene.index.SortedSetDocValues;
|
||||||
import org.apache.lucene.index.Terms;
|
import org.apache.lucene.index.Terms;
|
||||||
|
@ -1304,14 +1305,18 @@ class FieldCacheImpl implements FieldCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: this if DocTermsIndex was already created, we
|
||||||
|
// should share it...
|
||||||
public SortedSetDocValues getDocTermOrds(AtomicReader reader, String field) throws IOException {
|
public SortedSetDocValues getDocTermOrds(AtomicReader reader, String field) throws IOException {
|
||||||
SortedSetDocValues dv = reader.getSortedSetDocValues(field);
|
SortedSetDocValues dv = reader.getSortedSetDocValues(field);
|
||||||
if (dv != null) {
|
if (dv != null) {
|
||||||
return dv;
|
return dv;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nocommit: actually if they have a SortedDV (either indexed as DV or cached), we should return an impl
|
SortedDocValues sdv = reader.getSortedDocValues(field);
|
||||||
// over that: its like a specialized single-value case of this thing...
|
if (sdv != null) {
|
||||||
|
return new SingletonSortedSetDocValues(sdv);
|
||||||
|
}
|
||||||
|
|
||||||
DocTermOrds dto = (DocTermOrds) caches.get(DocTermOrds.class).get(reader, new CacheKey(field, null), false);
|
DocTermOrds dto = (DocTermOrds) caches.get(DocTermOrds.class).get(reader, new CacheKey(field, null), false);
|
||||||
return dto.iterator(dto.getOrdTermsEnum(reader));
|
return dto.iterator(dto.getOrdTermsEnum(reader));
|
||||||
|
@ -1325,7 +1330,6 @@ class FieldCacheImpl implements FieldCache {
|
||||||
@Override
|
@Override
|
||||||
protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField /* ignored */)
|
protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField /* ignored */)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
// No DocValues impl yet (DocValues are single valued...):
|
|
||||||
return new DocTermOrds(reader, key.field);
|
return new DocTermOrds(reader, key.field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,8 +254,11 @@ public class TestFieldCache extends LuceneTestCase {
|
||||||
|
|
||||||
// getDocTermOrds
|
// getDocTermOrds
|
||||||
SortedSetDocValues termOrds = cache.getDocTermOrds(reader, "theRandomUnicodeMultiValuedField");
|
SortedSetDocValues termOrds = cache.getDocTermOrds(reader, "theRandomUnicodeMultiValuedField");
|
||||||
// nocommit: test this with reflection or something, that its really from the same DTO
|
int numEntries = cache.getCacheEntries().length;
|
||||||
// assertSame("Second request to cache return same DocTermOrds", termOrds, cache.getDocTermOrds(reader, "theRandomUnicodeMultiValuedField"));
|
// ask for it again, and check that we didnt create any additional entries:
|
||||||
|
termOrds = cache.getDocTermOrds(reader, "theRandomUnicodeMultiValuedField");
|
||||||
|
assertEquals(numEntries, cache.getCacheEntries().length);
|
||||||
|
|
||||||
for (int i = 0; i < NUM_DOCS; i++) {
|
for (int i = 0; i < NUM_DOCS; i++) {
|
||||||
termOrds.setDocument(i);
|
termOrds.setDocument(i);
|
||||||
// This will remove identical terms. A DocTermOrds doesn't return duplicate ords for a docId
|
// This will remove identical terms. A DocTermOrds doesn't return duplicate ords for a docId
|
||||||
|
@ -275,8 +278,8 @@ public class TestFieldCache extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// test bad field
|
// test bad field
|
||||||
// nocommit: what exactly does this test?
|
|
||||||
termOrds = cache.getDocTermOrds(reader, "bogusfield");
|
termOrds = cache.getDocTermOrds(reader, "bogusfield");
|
||||||
|
assertTrue(termOrds.getValueCount() == 0);
|
||||||
|
|
||||||
FieldCache.DEFAULT.purge(reader);
|
FieldCache.DEFAULT.purge(reader);
|
||||||
}
|
}
|
||||||
|
|
|
@ -472,8 +472,8 @@ public class AssertingAtomicReader extends FilterAtomicReader {
|
||||||
public long nextOrd() {
|
public long nextOrd() {
|
||||||
assert lastOrd != NO_MORE_ORDS;
|
assert lastOrd != NO_MORE_ORDS;
|
||||||
long ord = in.nextOrd();
|
long ord = in.nextOrd();
|
||||||
assert ord == NO_MORE_ORDS || ord < valueCount;
|
assert ord < valueCount;
|
||||||
assert ord > lastOrd;
|
assert ord == NO_MORE_ORDS || ord > lastOrd;
|
||||||
lastOrd = ord;
|
lastOrd = ord;
|
||||||
return ord;
|
return ord;
|
||||||
}
|
}
|
||||||
|
@ -482,7 +482,7 @@ public class AssertingAtomicReader extends FilterAtomicReader {
|
||||||
public void setDocument(int docID) {
|
public void setDocument(int docID) {
|
||||||
assert docID >= 0 && docID < maxDoc : "docid=" + docID + ",maxDoc=" + maxDoc;
|
assert docID >= 0 && docID < maxDoc : "docid=" + docID + ",maxDoc=" + maxDoc;
|
||||||
in.setDocument(docID);
|
in.setDocument(docID);
|
||||||
lastOrd = -1;
|
lastOrd = -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue