SOLR-1318: explain may use top-level searcher for field cache

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@799698 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2009-07-31 18:59:47 +00:00
parent 18078af958
commit 855ac03bfd
6 changed files with 75 additions and 3 deletions

View File

@ -282,6 +282,7 @@ public class QueryComponent extends SearchComponent
break;
case SortField.CUSTOM:
comparator = sortField.getFactory().newComparator (reader, fieldname);
// comparator = sortField.getComparatorSource().newComparator(fieldname,2,1,false);
break;
default:
throw new RuntimeException ("unknown field type: "+sortField.getType());

View File

@ -47,7 +47,27 @@ public class FloatField extends FieldType {
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
writer.writeFloat(name, f.stringValue());
String s = f.stringValue();
// these values may be from a legacy lucene index, which may
// not be properly formatted in some output formats, or may
// incorrectly have a zero length.
if (s.length()==0) {
// zero length value means someone mistakenly indexed the value
// instead of simply leaving it out. Write a null value instead of a numeric.
writer.writeNull(name);
return;
}
try {
float fval = Float.parseFloat(s);
writer.writeFloat(name, fval);
} catch (NumberFormatException e){
// can't parse - write out the contents as a string so nothing is lost and
// clients don't get a parse error.
writer.writeStr(name, s, true);
}
}
@Override

View File

@ -205,6 +205,26 @@ public class TrieField extends FieldType {
return query;
}
@Override
public String toInternal(String val) {
return super.toInternal(val);
}
@Override
public String toExternal(Fieldable f) {
return super.toExternal(f);
}
@Override
public String indexedToReadable(String indexedForm) {
return super.indexedToReadable(indexedForm);
}
@Override
public String storedToIndexed(Fieldable f) {
return super.storedToIndexed(f);
}
public enum TrieTypes {
INTEGER,
LONG,

View File

@ -20,6 +20,7 @@ package org.apache.solr.search.function;
import org.apache.lucene.search.*;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.util.ToStringUtils;
import org.apache.solr.search.SolrIndexReader;
import java.io.IOException;
import java.util.Set;
@ -89,7 +90,24 @@ public class BoostedQuery extends Query {
}
public Explanation explain(IndexReader reader, int doc) throws IOException {
return scorer(reader).explain(doc);
SolrIndexReader topReader = (SolrIndexReader)reader;
SolrIndexReader[] subReaders = topReader.getLeafReaders();
int[] offsets = topReader.getLeafOffsets();
int readerPos = SolrIndexReader.readerIndex(doc, offsets);
int readerBase = offsets[readerPos];
Explanation subQueryExpl = qWeight.explain(reader,doc);
if (!subQueryExpl.isMatch()) {
return subQueryExpl;
}
DocValues vals = boostVal.getValues(subReaders[readerPos]);
float sc = subQueryExpl.getValue() * vals.floatVal(doc-readerBase);
Explanation res = new ComplexExplanation(
true, sc, BoostedQuery.this.toString() + ", product of:");
res.addDetail(subQueryExpl);
res.addDetail(vals.explain(doc-readerBase));
return res;
}
}

View File

@ -19,6 +19,8 @@ package org.apache.solr.search.function;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.*;
import org.apache.solr.search.SolrIndexReader;
import java.io.IOException;
import java.util.Set;
@ -84,7 +86,12 @@ public class FunctionQuery extends Query {
}
public Explanation explain(IndexReader reader, int doc) throws IOException {
return scorer(reader).explain(doc);
SolrIndexReader topReader = (SolrIndexReader)reader;
SolrIndexReader[] subReaders = topReader.getLeafReaders();
int[] offsets = topReader.getLeafOffsets();
int readerPos = SolrIndexReader.readerIndex(doc, offsets);
int readerBase = offsets[readerPos];
return scorer(subReaders[readerPos]).explain(doc-readerBase);
}
}

View File

@ -45,6 +45,7 @@ public class TestQueryTypes extends AbstractSolrTestCase {
assertU(adoc("id","5", "v_f","3.14159"));
assertU(adoc("id","6", "v_f","8983"));
assertU(adoc("id","7", "v_f","1.5"));
assertU(adoc("id","8", "v_ti","5"));
assertU(optimize());
@ -84,6 +85,11 @@ public class TestQueryTypes extends AbstractSolrTestCase {
,"//result[@numFound='1']"
);
assertQ(
req("q","{!field f=v_ti}5")
,"//result[@numFound='1']"
);
assertQ("test multi term field query on text type",
req("q","{!field f=v_t}Hello DUDE")
,"//result[@numFound='1']"