FileDocCategorySizeDatePackage
QueryTermVector.javaAPI DocApache Lucene 2.1.04114Wed Feb 14 10:46:40 GMT 2007org.apache.lucene.search

QueryTermVector

public class QueryTermVector extends Object implements TermFreqVector

Fields Summary
private String[]
terms
private int[]
termFreqs
Constructors Summary
public QueryTermVector(String[] queryTerms)

param
queryTerms The original list of terms from the query, can contain duplicates


    processTerms(queryTerms);
  
public QueryTermVector(String queryString, Analyzer analyzer)

    
    if (analyzer != null)
    {
      TokenStream stream = analyzer.tokenStream("", new StringReader(queryString));
      if (stream != null)
      {
        Token next = null;
        List terms = new ArrayList();
        try {
          while ((next = stream.next()) != null)
          {
            terms.add(next.termText());
          }
          processTerms((String[])terms.toArray(new String[terms.size()]));
        } catch (IOException e) {
        }
      }
    }                                                              
  
Methods Summary
public java.lang.StringgetField()


      return null;  
public int[]getTermFrequencies()

    return termFreqs;
  
public java.lang.String[]getTerms()

    return terms;
  
public intindexOf(java.lang.String term)

    int res = Arrays.binarySearch(terms, term);
        return res >= 0 ? res : -1;
  
public int[]indexesOf(java.lang.String[] terms, int start, int len)

    int res[] = new int[len];

    for (int i=0; i < len; i++) {
        res[i] = indexOf(terms[i]);
    }
    return res;                  
  
private voidprocessTerms(java.lang.String[] queryTerms)

    if (queryTerms != null) {
      Arrays.sort(queryTerms);
      Map tmpSet = new HashMap(queryTerms.length);
      //filter out duplicates
      List tmpList = new ArrayList(queryTerms.length);
      List tmpFreqs = new ArrayList(queryTerms.length);
      int j = 0;
      for (int i = 0; i < queryTerms.length; i++) {
        String term = queryTerms[i];
        Integer position = (Integer)tmpSet.get(term);
        if (position == null) {
          tmpSet.put(term, new Integer(j++));
          tmpList.add(term);
          tmpFreqs.add(new Integer(1));
        }       
        else {
          Integer integer = (Integer)tmpFreqs.get(position.intValue());
          tmpFreqs.set(position.intValue(), new Integer(integer.intValue() + 1));          
        }
      }
      terms = (String[])tmpList.toArray(terms);
      //termFreqs = (int[])tmpFreqs.toArray(termFreqs);
      termFreqs = new int[tmpFreqs.size()];
      int i = 0;
      for (Iterator iter = tmpFreqs.iterator(); iter.hasNext();) {
        Integer integer = (Integer) iter.next();
        termFreqs[i++] = integer.intValue();
      }
    }
  
public intsize()

    return terms.length;
  
public final java.lang.StringtoString()

        StringBuffer sb = new StringBuffer();
        sb.append('{");
        for (int i=0; i<terms.length; i++) {
            if (i>0) sb.append(", ");
            sb.append(terms[i]).append('/").append(termFreqs[i]);
        }
        sb.append('}");
        return sb.toString();