lucene 4: Moved SearchScript from IndexReader to AtomicReader. This also touches the seach/lookup classes
This commit is contained in:
parent
d820bfe11b
commit
48b8d0544f
|
@ -19,7 +19,7 @@
|
|||
|
||||
package org.elasticsearch.script;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.AtomicReader;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
import org.elasticsearch.search.lookup.DocLookup;
|
||||
import org.elasticsearch.search.lookup.FieldsLookup;
|
||||
|
@ -83,7 +83,7 @@ public abstract class AbstractSearchScript extends AbstractExecutableScript impl
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setNextReader(IndexReader reader) {
|
||||
public void setNextReader(AtomicReader reader) {
|
||||
lookup.setNextReader(reader);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.script;
|
||||
|
||||
import org.apache.lucene.index.AtomicReader;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
|
||||
|
@ -33,7 +34,7 @@ public interface SearchScript extends ExecutableScript {
|
|||
|
||||
void setScorer(Scorer scorer);
|
||||
|
||||
void setNextReader(IndexReader reader);
|
||||
void setNextReader(AtomicReader reader);
|
||||
|
||||
void setNextDocId(int doc);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package org.elasticsearch.script.mvel;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.AtomicReader;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
|
@ -163,7 +163,7 @@ public class MvelScriptEngineService extends AbstractComponent implements Script
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setNextReader(IndexReader reader) {
|
||||
public void setNextReader(AtomicReader reader) {
|
||||
lookup.setNextReader(reader);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.search.lookup;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.apache.lucene.index.AtomicReader;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
import org.elasticsearch.ElasticSearchException;
|
||||
|
@ -52,7 +53,7 @@ public class DocLookup implements Map {
|
|||
@Nullable
|
||||
private final String[] types;
|
||||
|
||||
private IndexReader reader;
|
||||
private AtomicReader reader;
|
||||
|
||||
private Scorer scorer;
|
||||
|
||||
|
@ -72,7 +73,7 @@ public class DocLookup implements Map {
|
|||
return this.fieldDataCache;
|
||||
}
|
||||
|
||||
public void setNextReader(IndexReader reader) {
|
||||
public void setNextReader(AtomicReader reader) {
|
||||
if (this.reader == reader) { // if we are called with the same reader, don't invalidate source
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.search.lookup;
|
|||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.IndexableField;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -84,7 +85,7 @@ public class FieldLookup {
|
|||
}
|
||||
valueLoaded = true;
|
||||
value = null;
|
||||
Fieldable field = doc.getFieldable(mapper.names().indexName());
|
||||
IndexableField field = doc.getField(mapper.names().indexName());
|
||||
if (field == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -98,8 +99,8 @@ public class FieldLookup {
|
|||
}
|
||||
valuesLoaded = true;
|
||||
values.clear();
|
||||
Fieldable[] fields = doc.getFieldables(mapper.names().indexName());
|
||||
for (Fieldable field : fields) {
|
||||
IndexableField[] fields = doc.getFields(mapper.names().indexName());
|
||||
for (IndexableField field : fields) {
|
||||
values.add(mapper.value(field));
|
||||
}
|
||||
return values;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.search.lookup;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.apache.lucene.index.AtomicReader;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||
import org.elasticsearch.ElasticSearchParseException;
|
||||
|
@ -44,7 +45,7 @@ public class FieldsLookup implements Map {
|
|||
@Nullable
|
||||
private final String[] types;
|
||||
|
||||
private IndexReader reader;
|
||||
private AtomicReader reader;
|
||||
|
||||
private int docId = -1;
|
||||
|
||||
|
@ -57,7 +58,7 @@ public class FieldsLookup implements Map {
|
|||
this.types = types;
|
||||
}
|
||||
|
||||
public void setNextReader(IndexReader reader) {
|
||||
public void setNextReader(AtomicReader reader) {
|
||||
if (this.reader == reader) { // if we are called with the same reader, don't invalidate source
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.search.lookup;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.lucene.index.AtomicReader;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
@ -66,7 +67,7 @@ public class SearchLookup {
|
|||
docMap.setScorer(scorer);
|
||||
}
|
||||
|
||||
public void setNextReader(IndexReader reader) {
|
||||
public void setNextReader(AtomicReader reader) {
|
||||
docMap.setNextReader(reader);
|
||||
sourceLookup.setNextReader(reader);
|
||||
fieldsLookup.setNextReader(reader);
|
||||
|
|
|
@ -22,7 +22,10 @@ package org.elasticsearch.search.lookup;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.AtomicReader;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.IndexableField;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.elasticsearch.ElasticSearchParseException;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
|
@ -41,7 +44,7 @@ import java.util.Set;
|
|||
// TODO: If we are processing it in the per hit fetch phase, we cna initialize it with a source if it was loaded..
|
||||
public class SourceLookup implements Map {
|
||||
|
||||
private IndexReader reader;
|
||||
private AtomicReader reader;
|
||||
|
||||
private int docId = -1;
|
||||
|
||||
|
@ -62,11 +65,12 @@ public class SourceLookup implements Map {
|
|||
}
|
||||
try {
|
||||
Document doc = reader.document(docId, SourceFieldSelector.INSTANCE);
|
||||
Fieldable sourceField = doc.getFieldable(SourceFieldMapper.NAME);
|
||||
IndexableField sourceField = doc.getField(SourceFieldMapper.NAME);
|
||||
if (sourceField == null) {
|
||||
source = ImmutableMap.of();
|
||||
} else {
|
||||
this.source = sourceAsMap(sourceField.getBinaryValue(), sourceField.getBinaryOffset(), sourceField.getBinaryLength());
|
||||
BytesRef source = sourceField.binaryValue();
|
||||
this.source = sourceAsMap(source.bytes, source.offset, source.length);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ElasticSearchParseException("failed to parse / load source", e);
|
||||
|
@ -82,7 +86,7 @@ public class SourceLookup implements Map {
|
|||
return XContentHelper.convertToMap(bytes, offset, length, false).v2();
|
||||
}
|
||||
|
||||
public void setNextReader(IndexReader reader) {
|
||||
public void setNextReader(AtomicReader reader) {
|
||||
if (this.reader == reader) { // if we are called with the same reader, don't invalidate source
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue