lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r897449 - in /lucene/java/trunk/contrib: CHANGES.txt snowball/src/java/org/apache/lucene/analysis/snowball/SnowballFilter.java snowball/src/java/org/tartarus/snowball/SnowballProgram.java
Date Sat, 09 Jan 2010 13:34:12 GMT
Author: rmuir
Date: Sat Jan  9 13:34:11 2010
New Revision: 897449

URL: http://svn.apache.org/viewvc?rev=897449&view=rev
Log:
LUCENE-2194: Improve the efficiency of Snowball

Modified:
    lucene/java/trunk/contrib/CHANGES.txt
    lucene/java/trunk/contrib/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballFilter.java
    lucene/java/trunk/contrib/snowball/src/java/org/tartarus/snowball/SnowballProgram.java

Modified: lucene/java/trunk/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/CHANGES.txt?rev=897449&r1=897448&r2=897449&view=diff
==============================================================================
--- lucene/java/trunk/contrib/CHANGES.txt (original)
+++ lucene/java/trunk/contrib/CHANGES.txt Sat Jan  9 13:34:11 2010
@@ -86,6 +86,9 @@
    take advantage of this for faster performance.
    (Steven Rowe, Uwe Schindler, Robert Muir)
 
+ * LUCENE-2194: Improve the efficiency of Snowball by not creating 2 new Strings
+   and 1 new StringBuilder for every word.  (Robert Muir)
+
 Test Cases
 
  * LUCENE-2115: Cutover contrib tests to use Java5 generics.  (Kay Kay

Modified: lucene/java/trunk/contrib/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballFilter.java?rev=897449&r1=897448&r2=897449&view=diff
==============================================================================
--- lucene/java/trunk/contrib/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballFilter.java
(original)
+++ lucene/java/trunk/contrib/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballFilter.java
Sat Jan  9 13:34:11 2010
@@ -74,13 +74,16 @@
   @Override
   public final boolean incrementToken() throws IOException {
     if (input.incrementToken()) {
-      String originalTerm = termAtt.term();
-      stemmer.setCurrent(originalTerm);
+      char termBuffer[] = termAtt.termBuffer();
+      final int length = termAtt.termLength();
+      stemmer.setCurrent(termBuffer, 0, length);
       stemmer.stem();
-      String finalTerm = stemmer.getCurrent();
-      // Don't bother updating, if it is unchanged.
-      if (!originalTerm.equals(finalTerm))
-        termAtt.setTermBuffer(finalTerm);
+      final StringBuilder finalTerm = stemmer.getCurrentBuffer();
+      final int newLength = finalTerm.length();
+      if (newLength > termBuffer.length)
+        termBuffer = termAtt.resizeTermBuffer(newLength);
+      finalTerm.getChars(0, newLength, termBuffer, 0);
+      termAtt.setTermLength(newLength);
       return true;
     } else {
       return false;

Modified: lucene/java/trunk/contrib/snowball/src/java/org/tartarus/snowball/SnowballProgram.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/snowball/src/java/org/tartarus/snowball/SnowballProgram.java?rev=897449&r1=897448&r2=897449&view=diff
==============================================================================
--- lucene/java/trunk/contrib/snowball/src/java/org/tartarus/snowball/SnowballProgram.java
(original)
+++ lucene/java/trunk/contrib/snowball/src/java/org/tartarus/snowball/SnowballProgram.java
Sat Jan  9 13:34:11 2010
@@ -77,6 +77,26 @@
         current = new StringBuilder();
         return result;
     }
+    
+    /**
+     * Set the current string.
+     */
+    public void setCurrent(char text[], int offset, int length) {
+      current.setLength(0);
+      current.append(text, offset, length);
+      cursor = 0;
+      limit = current.length();
+      limit_backward = 0;
+      bra = cursor;
+      ket = limit;
+    }
+
+    /**
+     * Get the current buffer containing the stem
+     */
+    public StringBuilder getCurrentBuffer() {
+      return current;
+    }
 
     // current string
     protected StringBuilder current;



Mime
View raw message