lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1230585 - /lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/UserDictionary.java
Date Thu, 12 Jan 2012 15:17:18 GMT
Author: rmuir
Date: Thu Jan 12 15:17:17 2012
New Revision: 1230585

URL: http://svn.apache.org/viewvc?rev=1230585&view=rev
Log:
LUCENE-3305: return placeholder if we found no results in user dictionary for the input

Modified:
    lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/UserDictionary.java

Modified: lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/UserDictionary.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/UserDictionary.java?rev=1230585&r1=1230584&r2=1230585&view=diff
==============================================================================
--- lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/UserDictionary.java
(original)
+++ lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/UserDictionary.java
Thu Jan 12 15:17:17 2012
@@ -132,7 +132,8 @@ public final class UserDictionary implem
   public int[][] lookup(char[] chars, int off, int len) throws IOException {
     // TODO: can we avoid this treemap/toIndexArray?
     TreeMap<Integer, int[]> result = new TreeMap<Integer, int[]>(); // index,
[length, length...]
-    
+    boolean found = false; // true if we found any results
+
     FST.Arc<Long> arc = new FST.Arc<Long>();
     int end = off + len;
     for (int startOffset = off; startOffset < end; startOffset++) {
@@ -148,13 +149,16 @@ public final class UserDictionary implem
         if (arc.isFinal()) {
           output += arc.nextFinalOutput.intValue();
           result.put(startOffset-off, segmentations[output]);
+          found = true;
         }
       }
     }
     
-    return toIndexArray(result);
+    return found ? toIndexArray(result) : EMPTY_RESULT;
   }
   
+  private static final int[][] EMPTY_RESULT = new int[0][];
+  
   /**
    * Convert Map of index and wordIdAndLength to array of {wordId, index, length}
    * @param input



Mime
View raw message