lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r821556 - in /lucene/solr/trunk: ./ src/java/org/apache/solr/handler/component/ src/java/org/apache/solr/schema/ src/java/org/apache/solr/search/
Date Sun, 04 Oct 2009 16:26:06 GMT
Author: markrmiller
Date: Sun Oct  4 16:26:06 2009
New Revision: 821556

URL: http://svn.apache.org/viewvc?rev=821556&view=rev
Log:
SOLR-1221: Change Solr Highlighting to use the SpanScorer with MultiTerm expansion by default

Added:
    lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryWrapper.java
Modified:
    lucene/solr/trunk/CHANGES.txt
    lucene/solr/trunk/src/java/org/apache/solr/handler/component/HighlightComponent.java
    lucene/solr/trunk/src/java/org/apache/solr/schema/TrieDateField.java
    lucene/solr/trunk/src/java/org/apache/solr/schema/TrieField.java
    lucene/solr/trunk/src/java/org/apache/solr/search/QueryParsing.java

Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=821556&r1=821555&r2=821556&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Sun Oct  4 16:26:06 2009
@@ -518,7 +518,7 @@
     international non-letter characters such as non spacing marks. (yonik)
     
 46. SOLR-825, SOLR-1221: Enables highlighting for range/wildcard/fuzzy/prefix queries if
using hl.usePhraseHighlighter=true
-    and hl.highlightMultiTerm=true. Also make both options default to true. (Mark Miller)
+    and hl.highlightMultiTerm=true. Also make both options default to true. (Mark Miller,
yonik)
 
 47. SOLR-1174: Fix Logging admin form submit url for multicore. (Jacob Singh via shalin)
 

Modified: lucene/solr/trunk/src/java/org/apache/solr/handler/component/HighlightComponent.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/component/HighlightComponent.java?rev=821556&r1=821555&r2=821556&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/component/HighlightComponent.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/component/HighlightComponent.java Sun
Oct  4 16:26:06 2009
@@ -80,7 +80,7 @@
       }
       
       if(highlightQuery != null) {
-        boolean rewrite = !(Boolean.valueOf(req.getParams().get(HighlightParams.USE_PHRASE_HIGHLIGHTER))
&& Boolean.valueOf(req.getParams().get(HighlightParams.HIGHLIGHT_MULTI_TERM)));
+        boolean rewrite = !(Boolean.valueOf(req.getParams().get(HighlightParams.USE_PHRASE_HIGHLIGHTER,
"true")) && Boolean.valueOf(req.getParams().get(HighlightParams.HIGHLIGHT_MULTI_TERM,
"true")));
         highlightQuery = rewrite ?  highlightQuery.rewrite(req.getSearcher().getReader())
: highlightQuery;
       }
       

Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/TrieDateField.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/TrieDateField.java?rev=821556&r1=821555&r2=821556&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/TrieDateField.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/TrieDateField.java Sun Oct  4 16:26:06
2009
@@ -24,6 +24,7 @@
 import org.apache.solr.analysis.TrieTokenizerFactory;
 import org.apache.solr.search.function.*;
 import org.apache.solr.search.QParser;
+import org.apache.solr.search.SolrQueryWrapper;
 import org.apache.solr.request.XMLWriter;
 import org.apache.solr.request.TextResponseWriter;
 import org.apache.lucene.document.Fieldable;
@@ -203,6 +204,10 @@
               min == null ? null : min.getTime(),
               max == null ? null : max.getTime(),
               minInclusive, maxInclusive);
-    return query;
+
+    // NumericRangeQuery extends MultiTermQuery but returns null for getTerm() which currently
breaks
+    // the span based highlighter in Lucene 2.9.0.  Wrapping the query prevents the highlighter
+    // from calling getTerm()
+    return new SolrQueryWrapper(query);
   }
 }

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=821556&r1=821555&r2=821556&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 Sun Oct  4 16:26:06 2009
@@ -18,23 +18,23 @@
 
 import org.apache.lucene.document.Fieldable;
 import org.apache.lucene.document.Field;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.SortField;
-import org.apache.lucene.search.NumericRangeQuery;
-import org.apache.lucene.search.FieldCache;
+import org.apache.lucene.search.*;
 import org.apache.lucene.util.NumericUtils;
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.NumericTokenStream;
+import org.apache.lucene.index.IndexReader;
 import org.apache.solr.analysis.*;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.request.TextResponseWriter;
 import org.apache.solr.request.XMLWriter;
 import org.apache.solr.search.QParser;
+import org.apache.solr.search.SolrQueryWrapper;
 import org.apache.solr.search.function.*;
 
 import java.io.IOException;
 import java.util.Map;
 import java.util.Date;
+import java.util.Set;
 
 /**
  * Provides field types to support for Lucene's Trie Range Queries.
@@ -260,7 +260,10 @@
         throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie
field");
     }
 
-    return query;
+    // NumericRangeQuery extends MultiTermQuery but returns null for getTerm() which currently
breaks
+    // the span based highlighter in Lucene 2.9.0.  Wrapping the query prevents the highlighter
+    // from calling getTerm()
+    return new SolrQueryWrapper(query);
   }
 
 
@@ -482,4 +485,6 @@
   public long externalToLong(String extVal) {
     return TrieField.dateField.parseMath(null, extVal).getTime();
   }
-}
\ No newline at end of file
+}
+
+

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/QueryParsing.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/QueryParsing.java?rev=821556&r1=821555&r2=821556&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/QueryParsing.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/QueryParsing.java Sun Oct  4 16:26:06
2009
@@ -29,6 +29,7 @@
 import org.apache.solr.schema.FieldType;
 import org.apache.solr.schema.IndexSchema;
 import org.apache.solr.schema.SchemaField;
+import org.apache.solr.search.SolrQueryWrapper;
 import org.apache.solr.search.function.FunctionQuery;
 
 import java.io.IOException;
@@ -440,6 +441,9 @@
     } else if (query instanceof ConstantScoreQuery) {
       out.append(query.toString());
       writeBoost=false;
+    } else if (query instanceof SolrQueryWrapper) {
+      toString(((SolrQueryWrapper)query).getWrappedQuery(), schema, out, flags);
+      return;
     } else {
       out.append(query.getClass().getSimpleName()
               + '(' + query.toString() + ')' );

Added: lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryWrapper.java?rev=821556&view=auto
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryWrapper.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryWrapper.java Sun Oct  4 16:26:06
2009
@@ -0,0 +1,112 @@
+/**
+ * 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.solr.search;
+
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Weight;
+import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.Similarity;
+import org.apache.lucene.index.IndexReader;
+
+import java.io.IOException;
+import java.util.Set;
+
+public class SolrQueryWrapper extends Query {
+  private final Query q;
+  public SolrQueryWrapper(Query q) {
+    this.q = q;
+  }
+
+  public Query getWrappedQuery() {
+    return q;
+  }
+
+  @Override
+  public void setBoost(float b) {
+    q.setBoost(b);
+  }
+
+  @Override
+  public float getBoost() {
+    return q.getBoost();
+  }
+
+  @Override
+  public String toString() {
+    return q.toString();
+  }
+
+  @Override
+  public Weight createWeight(Searcher searcher) throws IOException {
+    return q.createWeight(searcher);
+  }
+
+  @Override
+  public Weight weight(Searcher searcher) throws IOException {
+    return q.weight(searcher);
+  }
+
+  @Override
+  public Query rewrite(IndexReader reader) throws IOException {
+    return q.rewrite(reader);
+  }
+
+  @Override
+  public Query combine(Query[] queries) {
+    return q.combine(queries);
+  }
+
+  @Override
+  public void extractTerms(Set terms) {
+    q.extractTerms(terms);
+  }
+
+  @Override
+  public Similarity getSimilarity(Searcher searcher) {
+    return q.getSimilarity(searcher);
+  }
+
+  @Override
+  public Object clone() {
+    return new SolrQueryWrapper((Query)q.clone());
+  }
+
+  @Override
+  public int hashCode() {
+    return q.hashCode();
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    Query other;
+    if (obj instanceof SolrQueryWrapper) {
+      other = ((SolrQueryWrapper)obj).q;
+    } else if (obj instanceof Query) {
+      other = (Query)obj;
+    } else {
+      return false;
+    }
+
+    return q.equals(other);
+  }
+
+  @Override
+  public String toString(String field) {
+    return q.toString();
+  }
+}



Mime
View raw message