You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by yo...@apache.org on 2006/02/03 00:01:52 UTC

svn commit: r374539 - in /incubator/solr/trunk/src: apps/SolarTest/ java/org/apache/solr/analysis/ java/org/apache/solr/schema/

Author: yonik
Date: Thu Feb  2 15:01:47 2006
New Revision: 374539

URL: http://svn.apache.org/viewcvs?rev=374539&view=rev
Log:
positionIncrementGap schema support

Added:
    incubator/solr/trunk/src/java/org/apache/solr/analysis/SolrAnalyzer.java
Modified:
    incubator/solr/trunk/src/apps/SolarTest/newtest.txt
    incubator/solr/trunk/src/apps/SolarTest/schema.xml
    incubator/solr/trunk/src/java/org/apache/solr/analysis/TokenizerChain.java
    incubator/solr/trunk/src/java/org/apache/solr/schema/BoolField.java
    incubator/solr/trunk/src/java/org/apache/solr/schema/FieldType.java
    incubator/solr/trunk/src/java/org/apache/solr/schema/IndexSchema.java

Modified: incubator/solr/trunk/src/apps/SolarTest/newtest.txt
URL: http://svn.apache.org/viewcvs/incubator/solr/trunk/src/apps/SolarTest/newtest.txt?rev=374539&r1=374538&r2=374539&view=diff
==============================================================================
--- incubator/solr/trunk/src/apps/SolarTest/newtest.txt (original)
+++ incubator/solr/trunk/src/apps/SolarTest/newtest.txt Thu Feb  2 15:01:47 2006
@@ -535,6 +535,22 @@
 id:13 AND syn:bar %//*[@numFound="1"]
 id:13 AND syn:baz %//*[@numFound="1"]
 
+
+#test position increment gaps between field values
+<delete><id>44</id></delete>
+<delete><id>45</id></delete>
+<add><doc><field name="id">44</field><field name="textgap">aa bb cc</field><field name="textgap">dd ee ff</field></doc></add>
+<add><doc><field name="id">45</field><field name="text">aa bb cc</field><field name="text">dd ee ff</field></doc></add>
+<commit/>
++id:44 +textgap:"aa bb cc"  %//*[@numFound="1"]
++id:44 +textgap:"dd ee ff"  %//*[@numFound="1"]
++id:44 +textgap:"cc dd"  %//*[@numFound="0"]
++id:44 +textgap:"cc dd"~100  %//*[@numFound="1"]
++id:44 +textgap:"bb cc dd ee"~90  %//*[@numFound="0"]
++id:44 +textgap:"bb cc dd ee"~100  %//*[@numFound="1"]
++id:45 +text:"cc dd"  %//*[@numFound="1"]
+
+
 #trigger output of custom value test
 values %%qt=test
 

Modified: incubator/solr/trunk/src/apps/SolarTest/schema.xml
URL: http://svn.apache.org/viewcvs/incubator/solr/trunk/src/apps/SolarTest/schema.xml?rev=374539&r1=374538&r2=374539&view=diff
==============================================================================
--- incubator/solr/trunk/src/apps/SolarTest/schema.xml (original)
+++ incubator/solr/trunk/src/apps/SolarTest/schema.xml Thu Feb  2 15:01:47 2006
@@ -225,7 +225,16 @@
     </fieldtype>
 
     <fieldtype  name="unstored" class="solar.StrField" indexed="true" stored="false"/>
-  </types>
+
+
+  <fieldtype name="textgap" class="solar.TextField" multiValued="true" positionIncrementGap="100">
+      <analyzer>
+          <tokenizer class="solar.WhitespaceTokenizerFactory"/>
+          <filter class="solar.LowerCaseFilterFactory"/>
+      </analyzer>
+  </fieldtype>
+
+ </types>
 
 
  <fields>
@@ -281,6 +290,8 @@
    <field name="sku1" type="skutype1" indexed="true" stored="true"/>
    <field name="sku2" type="skutype2" indexed="true" stored="true"/>
 
+   <field name="textgap" type="textgap" indexed="true" stored="true"/>
+
    <!-- Dynamic field definitions.  If a field name is not found, dynamicFields
         will be used if the name matches any of the patterns.
         RESTRICTION: the glob-like pattern in the name attribute must have
@@ -307,6 +318,7 @@
    <!-- for testing to ensure that longer patterns are matched first -->
    <dynamicField name="*aa"  type="string"  indexed="true" stored="true"/>
    <dynamicField name="*aaa" type="integer" indexed="false" stored="true"/>
+
 
 
  </fields>

Added: incubator/solr/trunk/src/java/org/apache/solr/analysis/SolrAnalyzer.java
URL: http://svn.apache.org/viewcvs/incubator/solr/trunk/src/java/org/apache/solr/analysis/SolrAnalyzer.java?rev=374539&view=auto
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/analysis/SolrAnalyzer.java (added)
+++ incubator/solr/trunk/src/java/org/apache/solr/analysis/SolrAnalyzer.java Thu Feb  2 15:01:47 2006
@@ -0,0 +1,19 @@
+package org.apache.solr.analysis;
+
+import org.apache.lucene.analysis.Analyzer;
+
+/**
+ * @author yonik
+ * @version $Id$
+ */
+public abstract class SolrAnalyzer extends Analyzer {
+  int posIncGap=0;
+  
+  public void setPositionIncrementGap(int gap) {
+    posIncGap=gap;
+  }
+
+  public int getPositionIncrementGap(String fieldName) {
+    return posIncGap;
+  }
+}

Modified: incubator/solr/trunk/src/java/org/apache/solr/analysis/TokenizerChain.java
URL: http://svn.apache.org/viewcvs/incubator/solr/trunk/src/java/org/apache/solr/analysis/TokenizerChain.java?rev=374539&r1=374538&r2=374539&view=diff
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/analysis/TokenizerChain.java (original)
+++ incubator/solr/trunk/src/java/org/apache/solr/analysis/TokenizerChain.java Thu Feb  2 15:01:47 2006
@@ -31,7 +31,7 @@
 // An analyzer that uses a tokenizer and a list of token filters to
 // create a TokenStream.
 //
-public class TokenizerChain extends Analyzer {
+public class TokenizerChain extends SolrAnalyzer {
   final private TokenizerFactory tokenizer;
   final private TokenFilterFactory[] filters;
 

Modified: incubator/solr/trunk/src/java/org/apache/solr/schema/BoolField.java
URL: http://svn.apache.org/viewcvs/incubator/solr/trunk/src/java/org/apache/solr/schema/BoolField.java?rev=374539&r1=374538&r2=374539&view=diff
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/schema/BoolField.java (original)
+++ incubator/solr/trunk/src/java/org/apache/solr/schema/BoolField.java Thu Feb  2 15:01:47 2006
@@ -25,6 +25,7 @@
 import org.apache.lucene.analysis.Tokenizer;
 import org.apache.lucene.document.Field;
 import org.apache.solr.request.XMLWriter;
+import org.apache.solr.analysis.SolrAnalyzer;
 
 import java.util.Map;
 import java.io.Reader;
@@ -54,7 +55,7 @@
   // handle single valued non-text fields (int,bool,etc) if needed.
 
 
-  protected final static Analyzer boolAnalyzer = new Analyzer() {
+  protected final static Analyzer boolAnalyzer = new SolrAnalyzer() {
       public TokenStream tokenStream(String fieldName, Reader reader) {
         return new Tokenizer(reader) {
           boolean done=false;

Modified: incubator/solr/trunk/src/java/org/apache/solr/schema/FieldType.java
URL: http://svn.apache.org/viewcvs/incubator/solr/trunk/src/java/org/apache/solr/schema/FieldType.java?rev=374539&r1=374538&r2=374539&view=diff
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/schema/FieldType.java (original)
+++ incubator/solr/trunk/src/java/org/apache/solr/schema/FieldType.java Thu Feb  2 15:01:47 2006
@@ -26,6 +26,7 @@
 import org.apache.solr.search.function.OrdFieldSource;
 import org.apache.solr.search.Sorting;
 import org.apache.solr.request.XMLWriter;
+import org.apache.solr.analysis.SolrAnalyzer;
 
 import java.util.logging.Logger;
 import java.util.Map;
@@ -48,10 +49,6 @@
   protected int falseProperties;  // properties explicitly set to false
   int properties;
 
-  // these are common enough, they were moved to the base class to handle.
-  // not all subclasses will be able to support these options.
-  protected int positionIncrementGap;
-
   protected boolean isTokenized() {
     return (properties & TOKENIZED) != 0;
   }
@@ -73,12 +70,6 @@
     this.args=args;
     Map<String,String> initArgs = new HashMap<String,String>(args);
 
-    String str;
-
-    str = initArgs.get("positionIncrementGap");
-    if (str!=null) positionIncrementGap = Integer.parseInt(str);
-    initArgs.remove("positionIncrementGap");
-
     trueProperties = FieldProperties.parseProperties(initArgs,true);
     falseProperties = FieldProperties.parseProperties(initArgs,false);
 
@@ -89,6 +80,23 @@
 
     init(schema, initArgs);
 
+    String positionInc = initArgs.get("positionIncrementGap");
+    if (positionInc != null) {
+      Analyzer analyzer = getAnalyzer();
+      if (analyzer instanceof SolrAnalyzer) {
+        ((SolrAnalyzer)analyzer).setPositionIncrementGap(Integer.parseInt(positionInc));
+      } else {
+        throw new RuntimeException("Can't set positionIncrementGap on custom analyzer " + analyzer.getClass());
+      }
+      analyzer = getQueryAnalyzer();
+      if (analyzer instanceof SolrAnalyzer) {
+        ((SolrAnalyzer)analyzer).setPositionIncrementGap(Integer.parseInt(positionInc));
+      } else {
+        throw new RuntimeException("Can't set positionIncrementGap on custom analyzer " + analyzer.getClass());
+      }
+      initArgs.remove("positionIncrementGap");
+    }
+
     if (initArgs.size() > 0) {
       throw new RuntimeException("schema fieldtype " + typeName
               + "("+ this.getClass().getName() + ")"
@@ -195,7 +203,7 @@
   // Default analyzer for types that only produce 1 verbatim token...
   // A maximum size of chars to be read must be specified
   //
-  protected final class DefaultAnalyzer extends Analyzer {
+  protected final class DefaultAnalyzer extends SolrAnalyzer {
     final int maxChars;
 
     DefaultAnalyzer(int maxChars) {
@@ -212,10 +220,6 @@
           return new Token(s,0,n);
         };
       };
-    }
-
-    public int getPositionIncrementGap(String fieldName) {
-      return positionIncrementGap;
     }
   }
 

Modified: incubator/solr/trunk/src/java/org/apache/solr/schema/IndexSchema.java
URL: http://svn.apache.org/viewcvs/incubator/solr/trunk/src/java/org/apache/solr/schema/IndexSchema.java?rev=374539&r1=374538&r2=374539&view=diff
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/schema/IndexSchema.java (original)
+++ incubator/solr/trunk/src/java/org/apache/solr/schema/IndexSchema.java Thu Feb  2 15:01:47 2006
@@ -121,10 +121,10 @@
 
 
 
-  private class SolrAnalyzer extends Analyzer {
+  private class SolrIndexAnalyzer extends Analyzer {
     protected final HashMap<String,Analyzer> analyzers;
 
-    SolrAnalyzer() {
+    SolrIndexAnalyzer() {
       analyzers = analyzerCache();
     }
 
@@ -154,7 +154,7 @@
   }
 
 
-  private class SolrQueryAnalyzer extends SolrAnalyzer {
+  private class SolrQueryAnalyzer extends SolrIndexAnalyzer {
     protected HashMap<String,Analyzer> analyzerCache() {
       HashMap<String,Analyzer> cache = new HashMap<String,Analyzer>();
        for (SchemaField f : getFields().values()) {
@@ -348,7 +348,7 @@
       throw new SolrException(1,"Schema Parsing Failed",e,false);
     }
 
-     analyzer = new SolrAnalyzer();
+     analyzer = new SolrIndexAnalyzer();
      queryAnalyzer = new SolrQueryAnalyzer();
   }