Skip to content

Apache Lucene open-source search software

SOLR-2194 -- calculate correct value for JoinDocFreqValueSource when using a SubReader

Ryan McKinleyd2263013e982
diff --git a/solr/src/java/org/apache/solr/search/function/JoinDocFreqValueSource.java b/solr/src/java/org/apache/solr/search/function/JoinDocFreqValueSource.java
index fdafedd79b1..f93c9882e40 100644
--- a/solr/src/java/org/apache/solr/search/function/JoinDocFreqValueSource.java
+++ b/solr/src/java/org/apache/solr/search/function/JoinDocFreqValueSource.java
@@ -24,6 +24,7 @@ import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.FieldCache.DocTerms;
import org.apache.lucene.util.BytesRef;
import org.apache.solr.common.SolrException;
+import org.apache.solr.search.SolrIndexReader;
/**
* Use a field value and find the Document Frequency within another field.
@@ -45,19 +46,31 @@ public class JoinDocFreqValueSource extends FieldCacheSource {
return NAME + "(" + field +":("+qfield+"))";
}
- public DocValues getValues(Map context, final IndexReader reader) throws IOException
+ public DocValues getValues(Map context, IndexReader reader) throws IOException
{
final DocTerms terms = cache.getTerms(reader, field, true );
+ int offset = 0;
+ IndexReader topReader = reader;
+ if (topReader instanceof SolrIndexReader) {
+ SolrIndexReader r = (SolrIndexReader)topReader;
+ while (r.getParent() != null) {
+ offset += r.getBase();
+ r = r.getParent();
+ }
+ topReader = r;
+ }
+ final IndexReader top = topReader;
+
return new DocValues() {
+ BytesRef ref = new BytesRef();
public int intVal(int doc)
{
try {
- BytesRef ref = new BytesRef();
terms.getTerm(doc, ref);
- int v = reader.docFreq( qfield, ref );
- //System.out.println( NAME+"["+ref.utf8ToString()+"="+v+"]" );
+ int v = top.docFreq( qfield, ref );
+ //System.out.println( NAME+"["+field+"="+ref.utf8ToString()+"=("+qfield+":"+v+")]" );
return v;
}
catch (IOException e) {
diff --git a/solr/src/test/org/apache/solr/search/function/SortByFunctionTest.java b/solr/src/test/org/apache/solr/search/function/SortByFunctionTest.java
index e0fecfa1185..84eb1a9cb95 100644
--- a/solr/src/test/org/apache/solr/search/function/SortByFunctionTest.java
+++ b/solr/src/test/org/apache/solr/search/function/SortByFunctionTest.java
@@ -94,6 +94,7 @@ public class SortByFunctionTest extends AbstractSolrTestCase {
{
assertU(adoc("id", "4", "id_s", "D", "links_mfacet", "A", "links_mfacet", "B", "links_mfacet", "C" ) );
assertU(adoc("id", "3", "id_s", "C", "links_mfacet", "A", "links_mfacet", "B" ) );
+ assertU(commit()); // Make sure it uses two readers
assertU(adoc("id", "2", "id_s", "B", "links_mfacet", "A" ) );
assertU(adoc("id", "1", "id_s", "A" ) );
assertU(commit());