1 package org.apache.lucene.analysis; 2 3 18 19 32 33 public final class Token { 34 String termText; int startOffset; int endOffset; String type = "word"; 39 private int positionIncrement = 1; 40 41 43 public Token(String text, int start, int end) { 44 termText = text; 45 startOffset = start; 46 endOffset = end; 47 } 48 49 50 public Token(String text, int start, int end, String typ) { 51 termText = text; 52 startOffset = start; 53 endOffset = end; 54 type = typ; 55 } 56 57 82 public void setPositionIncrement(int positionIncrement) { 83 if (positionIncrement < 0) 84 throw new IllegalArgumentException 85 ("Increment must be zero or greater: " + positionIncrement); 86 this.positionIncrement = positionIncrement; 87 } 88 89 92 public int getPositionIncrement() { return positionIncrement; } 93 94 95 public final String termText() { return termText; } 96 97 103 public final int startOffset() { return startOffset; } 104 105 107 public final int endOffset() { return endOffset; } 108 109 110 public final String type() { return type; } 111 112 public final String toString() { 113 StringBuffer sb = new StringBuffer (); 114 sb.append("(" + termText + "," + startOffset + "," + endOffset); 115 if (!type.equals("word")) 116 sb.append(",type="+type); 117 if (positionIncrement != 1) 118 sb.append(",posIncr="+positionIncrement); 119 sb.append(")"); 120 return sb.toString(); 121 } 122 } 123 | Popular Tags |