lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r928371 - in /lucene/java/branches/flex_1458/src/java/org/apache/lucene: analysis/Token.java analysis/tokenattributes/TermToBytesRefAttribute.java util/BytesRef.java
Date Sun, 28 Mar 2010 10:21:37 GMT
Author: uschindler
Date: Sun Mar 28 10:21:37 2010
New Revision: 928371

URL: http://svn.apache.org/viewvc?rev=928371&view=rev
Log:
Optimize  Javadocs to prevent traps with TermsHash

Modified:
    lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/Token.java
    lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/tokenattributes/TermToBytesRefAttribute.java
    lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/BytesRef.java

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/Token.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/Token.java?rev=928371&r1=928370&r2=928371&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/Token.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/Token.java Sun Mar
28 10:21:37 2010
@@ -115,6 +115,7 @@ import org.apache.lucene.util.AttributeI
 
   @see org.apache.lucene.index.Payload
 */
+// TODO: change superclass to CharTermAttribute in 4.0!
 public class Token extends TermAttributeImpl 
                    implements TypeAttribute, PositionIncrementAttribute,
                               FlagsAttribute, OffsetAttribute, PayloadAttribute {

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/tokenattributes/TermToBytesRefAttribute.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/tokenattributes/TermToBytesRefAttribute.java?rev=928371&r1=928370&r2=928371&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/tokenattributes/TermToBytesRefAttribute.java
(original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/tokenattributes/TermToBytesRefAttribute.java
Sun Mar 28 10:21:37 2010
@@ -25,8 +25,23 @@ import org.apache.lucene.util.BytesRef;
  * This attribute has no real state, it should be implemented in addition to
  * {@link CharTermAttribute}, to support indexing the term text as
  * UTF-8 bytes.
+ * @lucene.experimental This is a very expert API, please use
+ * {@link CharTermAttributeImpl} and its implementation of this method
+ * for UTF-8 terms.
  */
 public interface TermToBytesRefAttribute extends Attribute {
-  /** Copies the token's term text into the given {@link BytesRef}. It returns the hashCode
for TermsHash */
-  public int toBytesRef(BytesRef bytes);
+  /** Copies the token's term text into the given {@link BytesRef}.
+   * @param termBytes destination to write the bytes to (UTF-8 for text terms).
+   * @return the hashcode as defined by {@link BytesRef#hashCode}:
+   * <pre>
+   *  int hash = 0;
+   *  for (int i = termBytes.offset; i &lt; termBytes.offset+termBytes.length; i++) {
+   *    hash = 31*hash + termBytes.bytes[i];
+   *  }
+   * </pre>
+   * Implement this for performance reasons, if your code can calculate
+   * the hash on-the-fly. If this is not the case, just return
+   * {@code termBytes.hashCode()}.
+   */
+  public int toBytesRef(BytesRef termBytes);
 }

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/BytesRef.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/BytesRef.java?rev=928371&r1=928370&r2=928371&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/BytesRef.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/BytesRef.java Sun Mar 28
10:21:37 2010
@@ -125,6 +125,15 @@ public final class BytesRef {
     return sliceEquals(other, length - other.length);
   }
   
+  /** Calculates the hash code as required by TermsHash during indexing.
+   * <p>It is defined as:
+   * <pre>
+   *  int hash = 0;
+   *  for (int i = offset; i &lt; offset + length; i++) {
+   *    hash = 31*hash + bytes[i];
+   *  }
+   * </pre>
+   */
   @Override
   public int hashCode() {
     final int prime = 31;



Mime
View raw message