lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r1694267 - in /lucene/dev/trunk/lucene: CHANGES.txt core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java core/src/test/org/apache/lucene/index/TestReaderWrapperDVTypeCheck.java
Date Wed, 05 Aug 2015 17:17:13 GMT
Author: yonik
Date: Wed Aug  5 17:17:12 2015
New Revision: 1694267

URL: http://svn.apache.org/r1694267
Log:
SOLR-7730: SlowCompositeReaderWrapper.getSortedSetDocValues - don't merge FieldInfos just
to check DocValueType

Added:
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestReaderWrapperDVTypeCheck.java
  (with props)
Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1694267&r1=1694266&r2=1694267&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Wed Aug  5 17:17:12 2015
@@ -427,6 +427,10 @@ Optimizations
   egothor/stemmer/Compile.java
   (Rishabh Patel via Christine Poerschke)
 
+* SOLR-7730: Speed up SlowCompositeReaderWrapper.getSortedSetDocValues() by
+  avoiding merging FieldInfos just to check doc value type.
+  (Mikhail Khludnev, yonik)
+
 Build
 
 * LUCENE-6518: Don't report false thread leaks from IBM J9

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java?rev=1694267&r1=1694266&r2=1694267&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java
(original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java
Wed Aug  5 17:17:12 2015
@@ -22,7 +22,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.lucene.util.Bits;
-
 import org.apache.lucene.index.MultiDocValues.MultiSortedDocValues;
 import org.apache.lucene.index.MultiDocValues.MultiSortedSetDocValues;
 import org.apache.lucene.index.MultiDocValues.OrdinalMap;
@@ -132,16 +131,17 @@ public final class SlowCompositeReaderWr
         return dv;
       }
     }
-    // cached ordinal map
-    if (getFieldInfos().fieldInfo(field).getDocValuesType() != DocValuesType.SORTED) {
-      return null;
-    }
     int size = in.leaves().size();
     final SortedDocValues[] values = new SortedDocValues[size];
     final int[] starts = new int[size+1];
     for (int i = 0; i < size; i++) {
       LeafReaderContext context = in.leaves().get(i);
-      SortedDocValues v = context.reader().getSortedDocValues(field);
+      final LeafReader reader = context.reader();
+      final FieldInfo fieldInfo = reader.getFieldInfos().fieldInfo(field);
+      if (fieldInfo != null && fieldInfo.getDocValuesType() != DocValuesType.SORTED)
{
+        return null;
+      }
+      SortedDocValues v = reader.getSortedDocValues(field);
       if (v == null) {
         v = DocValues.emptySorted();
       }
@@ -170,17 +170,19 @@ public final class SlowCompositeReaderWr
         return dv;
       }
     }
-    // cached ordinal map
-    if (getFieldInfos().fieldInfo(field).getDocValuesType() != DocValuesType.SORTED_SET)
{
-      return null;
-    }
+   
     assert map != null;
     int size = in.leaves().size();
     final SortedSetDocValues[] values = new SortedSetDocValues[size];
     final int[] starts = new int[size+1];
     for (int i = 0; i < size; i++) {
       LeafReaderContext context = in.leaves().get(i);
-      SortedSetDocValues v = context.reader().getSortedSetDocValues(field);
+      final LeafReader reader = context.reader();
+      final FieldInfo fieldInfo = reader.getFieldInfos().fieldInfo(field);
+      if(fieldInfo != null && fieldInfo.getDocValuesType() != DocValuesType.SORTED_SET){
+        return null;
+      }
+      SortedSetDocValues v = reader.getSortedSetDocValues(field);
       if (v == null) {
         v = DocValues.emptySortedSet();
       }

Added: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestReaderWrapperDVTypeCheck.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestReaderWrapperDVTypeCheck.java?rev=1694267&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestReaderWrapperDVTypeCheck.java
(added)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestReaderWrapperDVTypeCheck.java
Wed Aug  5 17:17:12 2015
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.index;
+
+import java.io.IOException;
+import java.util.Random;
+
+import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.document.SortedDocValuesField;
+import org.apache.lucene.document.SortedSetDocValuesField;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
+
+
+
+public class TestReaderWrapperDVTypeCheck extends LuceneTestCase {
+  
+  public void testNoDVFieldOnSegment() throws IOException{
+    Directory dir = newDirectory();
+    IndexWriterConfig cfg = new IndexWriterConfig(new MockAnalyzer(random())).setCodec(TestUtil.alwaysDocValuesFormat(TestUtil.getDefaultDocValuesFormat()));
+    RandomIndexWriter iw = new RandomIndexWriter(random(), dir, cfg);
+    
+    boolean sdvExist = false;
+    boolean ssdvExist = false;
+    
+    final long seed = random().nextLong();
+    {
+      final Random indexRandom = new Random(seed);
+      final int docs;
+      docs = indexRandom.nextInt(4);
+     // System.out.println("docs:"+docs);
+      
+      for(int i=0; i< docs; i++){
+        Document d = new Document();
+        d.add(newStringField("id", ""+i, Store.NO));
+        if (rarely(indexRandom)) {
+         // System.out.println("on:"+i+" rarely: true");
+          d.add(new SortedDocValuesField("sdv", new BytesRef(""+i)));
+          sdvExist = true;
+        }else{
+         // System.out.println("on:"+i+" rarely: false");
+        }
+        final int numSortedSet = indexRandom.nextInt(5)-3;
+        for (int j = 0; j < numSortedSet; ++j) {
+         // System.out.println("on:"+i+" add ssdv:"+j);
+          d.add(new SortedSetDocValuesField("ssdv", new BytesRef(""+j)));
+          ssdvExist = true;
+        }
+        iw.addDocument(d);
+        iw.commit();
+      }
+    }
+    final DirectoryReader reader = iw.getReader();
+    
+   // System.out.println("sdv:"+ sdvExist+ " ssdv:"+ssdvExist+", segs: "+reader.leaves().size()
+", "+reader.leaves());
+    
+    iw.close();
+    final LeafReader wrapper = SlowCompositeReaderWrapper.wrap(reader);
+    
+    {
+      //final Random indexRandom = new Random(seed);
+      final SortedDocValues sdv = wrapper.getSortedDocValues("sdv");
+      final SortedSetDocValues ssdv = wrapper.getSortedSetDocValues("ssdv");
+      
+      assertNull("confusing DV type", wrapper.getSortedDocValues("ssdv"));
+      assertNull("confusing DV type", wrapper.getSortedSetDocValues("sdv"));
+      
+      assertNull("absent field", wrapper.getSortedDocValues("NOssdv"));
+      assertNull("absent field", wrapper.getSortedSetDocValues("NOsdv"));
+      
+      assertTrue("optional sdv field", sdvExist == (sdv!=null));
+      assertTrue("optional ssdv field", ssdvExist == (ssdv!=null));
+    } 
+    reader.close();
+    
+    dir.close();
+  }
+  
+}



Mime
View raw message