lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r817783 - in /lucene/solr/trunk/src: java/org/apache/solr/schema/StrField.java java/org/apache/solr/search/SolrIndexReader.java test/org/apache/solr/search/TestIndexSearcher.java
Date Tue, 22 Sep 2009 19:23:12 GMT
Author: yonik
Date: Tue Sep 22 19:23:07 2009
New Revision: 817783

URL: http://svn.apache.org/viewvc?rev=817783&view=rev
Log:
SOLR-1452: deletes in segment cause different fieldcache instances

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/schema/StrField.java
    lucene/solr/trunk/src/java/org/apache/solr/search/SolrIndexReader.java
    lucene/solr/trunk/src/test/org/apache/solr/search/TestIndexSearcher.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/StrField.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/StrField.java?rev=817783&r1=817782&r2=817783&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/StrField.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/StrField.java Tue Sep 22 19:23:07 2009
@@ -51,7 +51,7 @@
   }
 
   public ValueSource getValueSource(SchemaField field, QParser parser) {
-    return super.getValueSource(field, parser);
+    return new StrFieldSource(field.getName());
   }
 }
 

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/SolrIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/SolrIndexReader.java?rev=817783&r1=817782&r2=817783&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/SolrIndexReader.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/SolrIndexReader.java Tue Sep 22 19:23:07
2009
@@ -493,6 +493,21 @@
   public void undeleteAll() throws StaleReaderException, CorruptIndexException, LockObtainFailedException,
IOException {
     in.undeleteAll();
   }
+
+  @Override
+  public Object getFieldCacheKey() {
+    return in.getFieldCacheKey();
+  }
+
+  @Override
+  public boolean getDisableFakeNorms() {
+    return in.getDisableFakeNorms();
+  }
+
+  @Override
+  public void setDisableFakeNorms(boolean disableFakeNorms) {
+    in.setDisableFakeNorms(disableFakeNorms);
+  }
 }
 
 

Modified: lucene/solr/trunk/src/test/org/apache/solr/search/TestIndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/search/TestIndexSearcher.java?rev=817783&r1=817782&r2=817783&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/search/TestIndexSearcher.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/search/TestIndexSearcher.java Tue Sep 22 19:23:07
2009
@@ -18,6 +18,13 @@
 
 import org.apache.solr.util.AbstractSolrTestCase;
 import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.schema.SchemaField;
+import org.apache.solr.search.function.ValueSource;
+import org.apache.solr.search.function.DocValues;
+import org.apache.lucene.search.FieldCache;
+
+import java.util.Map;
+import java.io.IOException;
 
 public class TestIndexSearcher extends AbstractSolrTestCase {
 
@@ -37,15 +44,31 @@
     super.tearDown();
   }
 
+  private String getStringVal(SolrQueryRequest sqr, String field, int doc) throws IOException
{
+    SchemaField sf = sqr.getSchema().getField(field);
+    ValueSource vs = sf.getType().getValueSource(sf, null);
+    Map context = ValueSource.newContext();
+    vs.createWeight(context, sqr.getSearcher());
+    SolrIndexReader sr = sqr.getSearcher().getReader();
+    int idx = SolrIndexReader.readerIndex(doc, sr.getLeafOffsets());
+    int base = sr.getLeafOffsets()[idx];
+    SolrIndexReader sub = sr.getLeafReaders()[idx];
+    DocValues vals = vs.getValues(context, sub);
+    return vals.strVal(doc-base);
+  }
+
+  public void testReopen() throws Exception {
 
-  public void testReopen() {
-    assertU(adoc("id","1", "v_t","Hello Dude"));
-    assertU(adoc("id","2", "v_t","Hello Yonik"));
+    assertU(adoc("id","1", "v_t","Hello Dude", "v_s","string1"));
+    assertU(adoc("id","2", "v_t","Hello Yonik", "v_s","string2"));
     assertU(commit());
 
     SolrQueryRequest sr1 = req("q","foo");
     SolrIndexReader r1 = sr1.getSearcher().getReader();
 
+    String sval1 = getStringVal(sr1, "v_s",0);
+    assertEquals("string1", sval1);
+
     assertU(adoc("id","3", "v_s","{!literal}"));
     assertU(adoc("id","4", "v_s","other stuff"));
     assertU(commit());
@@ -57,8 +80,11 @@
     // Didn't work w/ older versions of lucene2.9 going from segment -> multi
     assertEquals(r1.getLeafReaders()[0], r2.getLeafReaders()[0]);
 
+    // make sure the String returned is the exact same instance (i.e. same FieldCache instance)
+    assertTrue(sval1 == getStringVal(sr2,"v_s",0));
+
     assertU(adoc("id","5", "v_f","3.14159"));
-    assertU(adoc("id","6", "v_f","8983"));
+    assertU(adoc("id","6", "v_f","8983", "v_s","string6"));
     assertU(commit());
 
     SolrQueryRequest sr3 = req("q","foo");
@@ -91,5 +117,22 @@
     assertEquals(baseRefCount, r4.getRefCount());
     sr4.close();
     assertEquals(baseRefCount-1, r4.getRefCount());
+
+
+    SolrQueryRequest sr5 = req("q","foo");
+    SolrIndexReader r5 = sr5.getSearcher().getReader();
+    String beforeDelete = getStringVal(sr5, "v_s",1);
+
+    assertU(delI("1"));
+    assertU(commit());
+    SolrQueryRequest sr6 = req("q","foo");
+    SolrIndexReader r6 = sr4.getSearcher().getReader();
+    assertEquals(1, r6.getLeafReaders()[0].numDocs()); // only a single doc left in the first
segment
+    assertTrue( !r5.getLeafReaders()[0].equals(r6.getLeafReaders()[0]) );  // readers now
different
+    String afterDelete = getStringVal(sr6, "v_s",1);
+    assertTrue( beforeDelete == afterDelete );  // same field cache is used even though deletions
are different
+
+    sr5.close();
+    sr6.close();
   }
 }
\ No newline at end of file



Mime
View raw message