lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject lucene-solr:branch_6x: SOLR-9878: fix ReversedWildcardFilterFactory caching in query parser
Date Tue, 20 Dec 2016 21:50:56 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x b45293313 -> 1e22dd25b


SOLR-9878: fix ReversedWildcardFilterFactory caching in query parser


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/1e22dd25
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/1e22dd25
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/1e22dd25

Branch: refs/heads/branch_6x
Commit: 1e22dd25bf20844c71648c39028c48d2a9aa4e58
Parents: b452933
Author: Mikhail Khludnev <mkhl@apache.org>
Authored: Wed Dec 21 00:01:27 2016 +0300
Committer: Mikhail Khludnev <mkhl@apache.org>
Committed: Wed Dec 21 00:50:34 2016 +0300

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 +
 .../apache/solr/parser/SolrQueryParserBase.java |  2 +-
 .../TestReversedWildcardFilterFactory.java      | 44 +++++++++++++++++++-
 3 files changed, 46 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1e22dd25/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 9b58f8b..d2cb56c 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -252,6 +252,8 @@ Other Changes
 
 * SOLR-9874: Solr will reject CREATEALIAS requests if target collections don't exist (Tomás
Fernández Löbbe)
 
+* SOLR-9878: fixing lazy logic for retrieving ReversedWildcardFilterFactory in SolrQueryParserBase
(Mikhail Khludnev)
+
 ==================  6.3.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1e22dd25/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java b/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java
index 0f6c7ac..168bd49 100644
--- a/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java
+++ b/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java
@@ -787,7 +787,7 @@ public abstract class SolrQueryParserBase extends QueryBuilder {
   protected ReversedWildcardFilterFactory getReversedWildcardFilterFactory(FieldType fieldType)
{
     if (leadingWildcards == null) leadingWildcards = new HashMap<>();
     ReversedWildcardFilterFactory fac = leadingWildcards.get(fieldType);
-    if (fac != null || leadingWildcards.containsKey(fac)) {
+    if (fac != null || leadingWildcards.containsKey(fieldType)) {
       return fac;
     }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1e22dd25/solr/core/src/test/org/apache/solr/analysis/TestReversedWildcardFilterFactory.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/analysis/TestReversedWildcardFilterFactory.java
b/solr/core/src/test/org/apache/solr/analysis/TestReversedWildcardFilterFactory.java
index 269a2c5..3ccc352 100644
--- a/solr/core/src/test/org/apache/solr/analysis/TestReversedWildcardFilterFactory.java
+++ b/solr/core/src/test/org/apache/solr/analysis/TestReversedWildcardFilterFactory.java
@@ -15,6 +15,11 @@
  * limitations under the License.
  */
 package org.apache.solr.analysis;
+import static org.apache.lucene.analysis.BaseTokenStreamTestCase.assertTokenStreamContents;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
@@ -26,18 +31,23 @@ import org.apache.lucene.search.Query;
 import org.apache.lucene.util.automaton.Automaton;
 import org.apache.lucene.util.automaton.Operations;
 import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.parser.CharStream;
+import org.apache.solr.parser.ParseException;
+import org.apache.solr.parser.SolrQueryParserBase;
 import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.schema.FieldType;
 import org.apache.solr.schema.IndexSchema;
 import org.apache.solr.schema.IndexSchemaFactory;
 import org.apache.solr.search.QParser;
 import org.apache.solr.search.SolrQueryParser;
+import org.apache.solr.search.SyntaxError;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import static org.apache.lucene.analysis.BaseTokenStreamTestCase.*;
 
 public class TestReversedWildcardFilterFactory extends SolrTestCaseJ4 {
+
   Map<String,String> args = new HashMap<>();
   IndexSchema schema;
 
@@ -183,4 +193,36 @@ public class TestReversedWildcardFilterFactory extends SolrTestCaseJ4
{
         req("+id:1 +one:*omez*"),
         "//result[@numFound=1]");
   }
+  
+  private static final class SolrQParser extends SolrQueryParserBase {
+    @Override
+    public Query TopLevelQuery(String field) throws ParseException, SyntaxError {
+      return null;
+    }
+
+    @Override
+    public void ReInit(CharStream stream) {}
+
+    @Override
+    protected ReversedWildcardFilterFactory getReversedWildcardFilterFactory(FieldType fieldType)
{
+      return super.getReversedWildcardFilterFactory(fieldType);
+    }
+  }
+  
+  @Test 
+  public void testCachingInQueryParser() {
+    SolrQParser parser = new SolrQParser();
+    
+    SolrQueryRequest req = req();
+    String[] fields = new String[]{"one", "two", "three"};
+    String aField = fields[random().nextInt(fields.length)];
+    FieldType type = req.getSchema().getField(aField).getType();
+    
+    FieldType typeSpy = spy(type);
+    // calling twice 
+    parser.getReversedWildcardFilterFactory(typeSpy);
+    parser.getReversedWildcardFilterFactory(typeSpy);
+    // but it should reach only once 
+    verify(typeSpy, times(1)).getIndexAnalyzer();
+  }
 }


Mime
View raw message