lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r799698 - in /lucene/solr/trunk/src: java/org/apache/solr/handler/component/ java/org/apache/solr/schema/ java/org/apache/solr/search/function/ test/org/apache/solr/search/
Date Fri, 31 Jul 2009 18:59:48 GMT
Author: yonik
Date: Fri Jul 31 18:59:47 2009
New Revision: 799698

URL: http://svn.apache.org/viewvc?rev=799698&view=rev
Log:
SOLR-1318: explain may use top-level searcher for field cache

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/handler/component/QueryComponent.java
    lucene/solr/trunk/src/java/org/apache/solr/schema/FloatField.java
    lucene/solr/trunk/src/java/org/apache/solr/schema/TrieField.java
    lucene/solr/trunk/src/java/org/apache/solr/search/function/BoostedQuery.java
    lucene/solr/trunk/src/java/org/apache/solr/search/function/FunctionQuery.java
    lucene/solr/trunk/src/test/org/apache/solr/search/TestQueryTypes.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/handler/component/QueryComponent.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/component/QueryComponent.java?rev=799698&r1=799697&r2=799698&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/component/QueryComponent.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/component/QueryComponent.java Fri Jul
31 18:59:47 2009
@@ -282,6 +282,7 @@
         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());

Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/FloatField.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/FloatField.java?rev=799698&r1=799697&r2=799698&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/FloatField.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/FloatField.java Fri Jul 31 18:59:47
2009
@@ -47,7 +47,27 @@
   }
 
   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

Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/TrieField.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/TrieField.java?rev=799698&r1=799697&r2=799698&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/TrieField.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/TrieField.java Fri Jul 31 18:59:47 2009
@@ -205,6 +205,26 @@
     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,

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/function/BoostedQuery.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/function/BoostedQuery.java?rev=799698&r1=799697&r2=799698&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/function/BoostedQuery.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/function/BoostedQuery.java Fri Jul 31
18:59:47 2009
@@ -20,6 +20,7 @@
 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 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;
     }
   }
 

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/function/FunctionQuery.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/function/FunctionQuery.java?rev=799698&r1=799697&r2=799698&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/function/FunctionQuery.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/function/FunctionQuery.java Fri Jul
31 18:59:47 2009
@@ -19,6 +19,8 @@
 
 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 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);
     }
   }
 

Modified: lucene/solr/trunk/src/test/org/apache/solr/search/TestQueryTypes.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/search/TestQueryTypes.java?rev=799698&r1=799697&r2=799698&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/search/TestQueryTypes.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/search/TestQueryTypes.java Fri Jul 31 18:59:47
2009
@@ -45,6 +45,7 @@
     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 @@
             ,"//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']"



Mime
View raw message