1 package org.apache.lucene.index; 2 3 18 19 import java.util.*; 20 21 23 class SegmentTermVector implements TermFreqVector { 24 private String field; 25 private String terms[]; 26 private int termFreqs[]; 27 28 SegmentTermVector(String field, String terms[], int termFreqs[]) { 29 this.field = field; 30 this.terms = terms; 31 this.termFreqs = termFreqs; 32 } 33 34 38 public String getField() { 39 return field; 40 } 41 42 public String toString() { 43 StringBuffer sb = new StringBuffer (); 44 sb.append('{'); 45 sb.append(field).append(": "); 46 if(terms != null){ 47 for (int i=0; i<terms.length; i++) { 48 if (i>0) sb.append(", "); 49 sb.append(terms[i]).append('/').append(termFreqs[i]); 50 } 51 } 52 sb.append('}'); 53 54 return sb.toString(); 55 } 56 57 public int size() { 58 return terms == null ? 0 : terms.length; 59 } 60 61 public String [] getTerms() { 62 return terms; 63 } 64 65 public int[] getTermFrequencies() { 66 return termFreqs; 67 } 68 69 public int indexOf(String termText) { 70 if(terms == null) 71 return -1; 72 int res = Arrays.binarySearch(terms, termText); 73 return res >= 0 ? res : -1; 74 } 75 76 public int[] indexesOf(String [] termNumbers, int start, int len) { 77 int res[] = new int[len]; 83 84 for (int i=0; i < len; i++) { 85 res[i] = indexOf(termNumbers[start+ i]); 86 } 87 return res; 88 } 89 } 90 | Popular Tags |