lucene-core-2.9.4-dev

import org.apache.lucene.index.IndexReader;

class FilteredQuery$1
  extends Weight
{
  private float value;
  private final FilteredQuery this$0;
  
  FilteredQuery$1(FilteredQuery paramFilteredQuery, Weight paramWeight, Similarity paramSimilarity) {}
  
  public float getValue()
  {
    return value;
  }
  
  public float sumOfSquaredWeights()
    throws IOException
  {
    return val$weight.sumOfSquaredWeights() * this$0.getBoost() * this$0.getBoost();
  }
  
  public void normalize(float v)
  {
    val$weight.normalize(v);
    value = (val$weight.getValue() * this$0.getBoost());
  }
  
  public Explanation explain(IndexReader ir, int i)
    throws IOException
  {
    Explanation inner = val$weight.explain(ir, i);
    if (this$0.getBoost() != 1.0F)
    {
      Explanation preBoost = inner;
      inner = new Explanation(inner.getValue() * this$0.getBoost(), "product of:");
      inner.addDetail(new Explanation(this$0.getBoost(), "boost"));
      inner.addDetail(preBoost);
    }
    Filter f = this$0.filter;
    DocIdSet docIdSet = f.getDocIdSet(ir);
    DocIdSetIterator docIdSetIterator = docIdSet == null ? DocIdSet.EMPTY_DOCIDSET.iterator() : docIdSet.iterator();
    if (docIdSetIterator == null) {
      docIdSetIterator = DocIdSet.EMPTY_DOCIDSET.iterator();
    }
    if (docIdSetIterator.advance(i) == i) {
      return inner;
    }
    Explanation result = new Explanation(0.0F, "failure to match filter: " + f.toString());
    
    result.addDetail(inner);
    return result;
  }
  
  public Query getQuery()
  {
    return this$0;
  }
  
  public Scorer scorer(IndexReader indexReader, boolean scoreDocsInOrder, boolean topScorer)
    throws IOException
  {
    final Scorer scorer = val$weight.scorer(indexReader, true, false);
    if (scorer == null) {
      return null;
    }
    DocIdSet docIdSet = this$0.filter.getDocIdSet(indexReader);
    if (docIdSet == null) {
      return null;
    }
    final DocIdSetIterator docIdSetIterator = docIdSet.iterator();
    if (docIdSetIterator == null) {
      return null;
    }
    new Scorer(val$similarity)
    {
      private int doc = -1;
      
      private int advanceToCommon(int scorerDoc, int disiDoc)
        throws IOException
      {
        while (scorerDoc != disiDoc) {
          if (scorerDoc < disiDoc) {
            scorerDoc = scorer.advance(disiDoc);
          } else {
            disiDoc = docIdSetIterator.advance(scorerDoc);
          }
        }
        return scorerDoc;
      }
      
      /**
       * @deprecated
       */
      public boolean next()
        throws IOException
      {
        return nextDoc() != Integer.MAX_VALUE;
      }
      
      public int nextDoc()
        throws IOException
      {
        int disiDoc;
        int scorerDoc;
        return doc = ((disiDoc = docIdSetIterator.nextDoc()) != Integer.MAX_VALUE) && ((scorerDoc = scorer.nextDoc()) != Integer.MAX_VALUE) && (advanceToCommon(scorerDoc, disiDoc) != Integer.MAX_VALUE) ? scorer.docID() : Integer.MAX_VALUE;
      }
      
      /**
       * @deprecated
       */
      public int doc()
      {
        return scorer.doc();
      }
      
      public int docID()
      {
        return doc;
      }
      
      /**
       * @deprecated
       */
      public boolean skipTo(int i)
        throws IOException
      {
        return advance(i) != Integer.MAX_VALUE;
      }
      
      public int advance(int target)
        throws IOException
      {
        int disiDoc;
        int scorerDoc;
        return doc = ((disiDoc = docIdSetIterator.advance(target)) != Integer.MAX_VALUE) && ((scorerDoc = scorer.advance(disiDoc)) != Integer.MAX_VALUE) && (advanceToCommon(scorerDoc, disiDoc) != Integer.MAX_VALUE) ? scorer.docID() : Integer.MAX_VALUE;
      }
      
      public float score()
        throws IOException
      {
        return this$0.getBoost() * scorer.score();
      }
      
      public Explanation explain(int i)
        throws IOException
      {
        Explanation exp = scorer.explain(i);
        if (docIdSetIterator.advance(i) == i)
        {
          exp.setDescription("allowed by filter: " + exp.getDescription());
          exp.setValue(this$0.getBoost() * exp.getValue());
        }
        else
        {
          exp.setDescription("removed by filter: " + exp.getDescription());
          exp.setValue(0.0F);
        }
        return exp;
      }
    };
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.search.FilteredQuery.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.search;

import java.io.IOException;
import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.util.ToStringUtils;

public class FilteredQuery
  extends Query
{
  Query query;
  Filter filter;
  
  public FilteredQuery(Query query, Filter filter)
  {
    this.query = query;
    this.filter = filter;
  }
  
  public Weight createWeight(Searcher searcher)
    throws IOException
  {
    final Weight weight = query.createWeight(searcher);
    final Similarity similarity = query.getSimilarity(searcher);
    new Weight()
    {
      private float value;
      
      public float getValue()
      {
        return value;
      }
      
      public float sumOfSquaredWeights()
        throws IOException
      {
        return weight.sumOfSquaredWeights() * getBoost() * getBoost();
      }
      
      public void normalize(float v)
      {
        weight.normalize(v);
        value = (weight.getValue() * getBoost());
      }
      
      public Explanation explain(IndexReader ir, int i)
        throws IOException
      {
        Explanation inner = weight.explain(ir, i);
        if (getBoost() != 1.0F)
        {
          Explanation preBoost = inner;
          inner = new Explanation(inner.getValue() * getBoost(), "product of:");
          inner.addDetail(new Explanation(getBoost(), "boost"));
          inner.addDetail(preBoost);
        }
        Filter f = filter;
        DocIdSet docIdSet = f.getDocIdSet(ir);
        DocIdSetIterator docIdSetIterator = docIdSet == null ? DocIdSet.EMPTY_DOCIDSET.iterator() : docIdSet.iterator();
        if (docIdSetIterator == null) {
          docIdSetIterator = DocIdSet.EMPTY_DOCIDSET.iterator();
        }
        if (docIdSetIterator.advance(i) == i) {
          return inner;
        }
        Explanation result = new Explanation(0.0F, "failure to match filter: " + f.toString());
        
        result.addDetail(inner);
        return result;
      }
      
      public Query getQuery()
      {
        return FilteredQuery.this;
      }
      
      public Scorer scorer(IndexReader indexReader, boolean scoreDocsInOrder, boolean topScorer)
        throws IOException
      {
        final Scorer scorer = weight.scorer(indexReader, true, false);
        if (scorer == null) {
          return null;
        }
        DocIdSet docIdSet = filter.getDocIdSet(indexReader);
        if (docIdSet == null) {
          return null;
        }
        final DocIdSetIterator docIdSetIterator = docIdSet.iterator();
        if (docIdSetIterator == null) {
          return null;
        }
        new Scorer(similarity)
        {
          private int doc = -1;
          
          private int advanceToCommon(int scorerDoc, int disiDoc)
            throws IOException
          {
            while (scorerDoc != disiDoc) {
              if (scorerDoc < disiDoc) {
                scorerDoc = scorer.advance(disiDoc);
              } else {
                disiDoc = docIdSetIterator.advance(scorerDoc);
              }
            }
            return scorerDoc;
          }
          
          /**
           * @deprecated
           */
          public boolean next()
            throws IOException
          {
            return nextDoc() != Integer.MAX_VALUE;
          }
          
          public int nextDoc()
            throws IOException
          {
            int disiDoc;
            int scorerDoc;
            return doc = ((disiDoc = docIdSetIterator.nextDoc()) != Integer.MAX_VALUE) && ((scorerDoc = scorer.nextDoc()) != Integer.MAX_VALUE) && (advanceToCommon(scorerDoc, disiDoc) != Integer.MAX_VALUE) ? scorer.docID() : Integer.MAX_VALUE;
          }
          
          /**
           * @deprecated
           */
          public int doc()
          {
            return scorer.doc();
          }
          
          public int docID()
          {
            return doc;
          }
          
          /**
           * @deprecated
           */
          public boolean skipTo(int i)
            throws IOException
          {
            return advance(i) != Integer.MAX_VALUE;
          }
          
          public int advance(int target)
            throws IOException
          {
            int disiDoc;
            int scorerDoc;
            return doc = ((disiDoc = docIdSetIterator.advance(target)) != Integer.MAX_VALUE) && ((scorerDoc = scorer.advance(disiDoc)) != Integer.MAX_VALUE) && (advanceToCommon(scorerDoc, disiDoc) != Integer.MAX_VALUE) ? scorer.docID() : Integer.MAX_VALUE;
          }
          
          public float score()
            throws IOException
          {
            return getBoost() * scorer.score();
          }
          
          public Explanation explain(int i)
            throws IOException
          {
            Explanation exp = scorer.explain(i);
            if (docIdSetIterator.advance(i) == i)
            {
              exp.setDescription("allowed by filter: " + exp.getDescription());
              exp.setValue(getBoost() * exp.getValue());
            }
            else
            {
              exp.setDescription("removed by filter: " + exp.getDescription());
              exp.setValue(0.0F);
            }
            return exp;
          }
        };
      }
    };
  }
  
  public Query rewrite(IndexReader reader)
    throws IOException
  {
    Query rewritten = query.rewrite(reader);
    if (rewritten != query)
    {
      FilteredQuery clone = (FilteredQuery)clone();
      query = rewritten;
      return clone;
    }
    return this;
  }
  
  public Query getQuery()
  {
    return query;
  }
  
  public Filter getFilter()
  {
    return filter;
  }
  
  public void extractTerms(Set terms)
  {
    getQuery().extractTerms(terms);
  }
  
  public String toString(String s)
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append("filtered(");
    buffer.append(query.toString(s));
    buffer.append(")->");
    buffer.append(filter);
    buffer.append(ToStringUtils.boost(getBoost()));
    return buffer.toString();
  }
  
  public boolean equals(Object o)
  {
    if ((o instanceof FilteredQuery))
    {
      FilteredQuery fq = (FilteredQuery)o;
      return (query.equals(query)) && (filter.equals(filter)) && (getBoost() == fq.getBoost());
    }
    return false;
  }
  
  public int hashCode()
  {
    return query.hashCode() ^ filter.hashCode() + Float.floatToRawIntBits(getBoost());
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.search.FilteredQuery
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.search;

import java.io.IOException;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermEnum;

public abstract class FilteredTermEnum
  extends TermEnum
{
  protected Term currentTerm = null;
  protected TermEnum actualEnum = null;
  
  protected abstract boolean termCompare(Term paramTerm);
  
  public abstract float difference();
  
  protected abstract boolean endEnum();
  
  protected void setEnum(TermEnum actualEnum)
    throws IOException
  {
    this.actualEnum = actualEnum;
    
    Term term = actualEnum.term();
    if ((term != null) && (termCompare(term))) {
      currentTerm = term;
    } else {
      next();
    }
  }
  
  public int docFreq()
  {
    if (currentTerm == null) {
      return -1;
    }
    assert (actualEnum != null);
    return actualEnum.docFreq();
  }
  
  public boolean next()
    throws IOException
  {
    if (actualEnum == null) {
      return false;
    }
    currentTerm = null;
    while (currentTerm == null)
    {
      if (endEnum()) {
        return false;
      }
      if (actualEnum.next())
      {
        Term term = actualEnum.term();
        if (termCompare(term))
        {
          currentTerm = term;
          return true;
        }
      }
      else
      {
        return false;
      }
    }
    currentTerm = null;
    return false;
  }
  
  public Term term()
  {
    return currentTerm;
  }
  
  public void close()
    throws IOException
  {
    if (actualEnum != null) {
      actualEnum.close();
    }
    currentTerm = null;
    actualEnum = null;
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.search.FilteredTermEnum
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.search;

import org.apache.lucene.index.Term;

public class FuzzyQuery$ScoreTerm
{
  public Term term;
  public float score;
  
  public FuzzyQuery$ScoreTerm(Term term, float score)
  {
    this.term = term;
    this.score = score;
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.search.FuzzyQuery.ScoreTerm
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.search;

import org.apache.lucene.index.Term;
import org.apache.lucene.util.PriorityQueue;

public class FuzzyQuery$ScoreTermQueue
  extends PriorityQueue
{
  public FuzzyQuery$ScoreTermQueue(int size)
  {
    initialize(size);
  }
  
  protected boolean lessThan(Object a, Object b)
  {
    FuzzyQuery.ScoreTerm termA = (FuzzyQuery.ScoreTerm)a;
    FuzzyQuery.ScoreTerm termB = (FuzzyQuery.ScoreTerm)b;
    if (score == score) {
      return term.compareTo(term) > 0;
    }
    return score < score;
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.search.FuzzyQuery.ScoreTermQueue
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.search;

import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.util.PriorityQueue;
import org.apache.lucene.util.ToStringUtils;

public class FuzzyQuery
  extends MultiTermQuery
{
  public static final float defaultMinSimilarity = 0.5F;
  public static final int defaultPrefixLength = 0;
  private float minimumSimilarity;
  private int prefixLength;
  private boolean termLongEnough = false;
  protected Term term;
  
  public FuzzyQuery(Term term, float minimumSimilarity, int prefixLength)
    throws IllegalArgumentException
  {
    super(term);
    this.term = term;
    if (minimumSimilarity >= 1.0F) {
      throw new IllegalArgumentException("minimumSimilarity >= 1");
    }
    if (minimumSimilarity < 0.0F) {
      throw new IllegalArgumentException("minimumSimilarity < 0");
    }
    if (prefixLength < 0) {
      throw new IllegalArgumentException("prefixLength < 0");
    }
    if (term.text().length() > 1.0F / (1.0F - minimumSimilarity)) {
      termLongEnough = true;
    }
    this.minimumSimilarity = minimumSimilarity;
    this.prefixLength = prefixLength;
    rewriteMethod = SCORING_BOOLEAN_QUERY_REWRITE;
  }
  
  public FuzzyQuery(Term term, float minimumSimilarity)
    throws IllegalArgumentException
  {
    this(term, minimumSimilarity, 0);
  }
  
  public FuzzyQuery(Term term)
  {
    this(term, 0.5F, 0);
  }
  
  public float getMinSimilarity()
  {
    return minimumSimilarity;
  }
  
  public int getPrefixLength()
  {
    return prefixLength;
  }
  
  protected FilteredTermEnum getEnum(IndexReader reader)
    throws IOException
  {
    return new FuzzyTermEnum(reader, getTerm(), minimumSimilarity, prefixLength);
  }
  
  public Term getTerm()
  {
    return term;
  }
  
  public void setRewriteMethod(MultiTermQuery.RewriteMethod method)
  {
    throw new UnsupportedOperationException("FuzzyQuery cannot change rewrite method");
  }
  
  public Query rewrite(IndexReader reader)
    throws IOException
  {
    if (!termLongEnough) {
      return new TermQuery(term);
    }
    FilteredTermEnum enumerator = getEnum(reader);
    int maxClauseCount = BooleanQuery.getMaxClauseCount();
    ScoreTermQueue stQueue = new ScoreTermQueue(maxClauseCount);
    ScoreTerm reusableST = null;
    try
    {
      do
      {
        float score = 0.0F;
        Term t = enumerator.term();
        if (t != null)
        {
          score = enumerator.difference();
          if (reusableST == null)
          {
            reusableST = new ScoreTerm(t, score);
          }
          else
          {
            if (score < score) {
              continue;
            }
            score = score;
            term = t;
          }
          reusableST = (ScoreTerm)stQueue.insertWithOverflow(reusableST);
        }
      } while (enumerator.next());
    }
    finally
    {
      enumerator.close();
    }
    BooleanQuery query = new BooleanQuery(true);
    int size = stQueue.size();
    for (int i = 0; i < size; i++)
    {
      ScoreTerm st = (ScoreTerm)stQueue.pop();
      TermQuery tq = new TermQuery(term);
      tq.setBoost(getBoost() * score);
      query.add(tq, BooleanClause.Occur.SHOULD);
    }
    return query;
  }
  
  public String toString(String field)
  {
    StringBuffer buffer = new StringBuffer();
    if (!term.field().equals(field))
    {
      buffer.append(term.field());
      buffer.append(":");
    }
    buffer.append(term.text());
    buffer.append('~');
    buffer.append(Float.toString(minimumSimilarity));
    buffer.append(ToStringUtils.boost(getBoost()));
    return buffer.toString();
  }
  
  protected static class ScoreTerm
  {
    public Term term;
    public float score;
    
    public ScoreTerm(Term term, float score)
    {
      this.term = term;
      this.score = score;
    }
  }
  
  protected static class ScoreTermQueue
    extends PriorityQueue
  {
    public ScoreTermQueue(int size)
    {
      initialize(size);
    }
    
    protected boolean lessThan(Object a, Object b)
    {
      FuzzyQuery.ScoreTerm termA = (FuzzyQuery.ScoreTerm)a;
      FuzzyQuery.ScoreTerm termB = (FuzzyQuery.ScoreTerm)b;
      if (score == score) {
        return term.compareTo(term) > 0;
      }
      return score < score;
    }
  }
  
  public int hashCode()
  {
    int prime = 31;
    int result = super.hashCode();
    result = 31 * result + Float.floatToIntBits(minimumSimilarity);
    result = 31 * result + prefixLength;
    result = 31 * result + (term == null ? 0 : term.hashCode());
    return result;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (!super.equals(obj)) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    FuzzyQuery other = (FuzzyQuery)obj;
    if (Float.floatToIntBits(minimumSimilarity) != Float.floatToIntBits(minimumSimilarity)) {
      return false;
    }
    if (prefixLength != prefixLength) {
      return false;
    }
    if (term == null)
    {
      if (term != null) {
        return false;
      }
    }
    else if (!term.equals(term)) {
      return false;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.search.FuzzyQuery
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.search;

import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;

public final class FuzzyTermEnum
  extends FilteredTermEnum
{
  private static final int TYPICAL_LONGEST_WORD_IN_INDEX = 19;
  private int[][] d;
  private float similarity;
  private boolean endEnum = false;
  private Term searchTerm = null;
  private final String field;
  private final String text;
  private final String prefix;
  private final float minimumSimilarity;
  private final float scale_factor;
  private final int[] maxDistances = new int[19];
  
  public FuzzyTermEnum(IndexReader reader, Term term)
    throws IOException
  {
    this(reader, term, 0.5F, 0);
  }
  
  public FuzzyTermEnum(IndexReader reader, Term term, float minSimilarity)
    throws IOException
  {
    this(reader, term, minSimilarity, 0);
  }
  
  public FuzzyTermEnum(IndexReader reader, Term term, float minSimilarity, int prefixLength)
    throws IOException
  {
    if (minSimilarity >= 1.0F) {
      throw new IllegalArgumentException("minimumSimilarity cannot be greater than or equal to 1");
    }
    if (minSimilarity < 0.0F) {
      throw new IllegalArgumentException("minimumSimilarity cannot be less than 0");
    }
    if (prefixLength < 0) {
      throw new IllegalArgumentException("prefixLength cannot be less than 0");
    }
    minimumSimilarity = minSimilarity;
    scale_factor = (1.0F / (1.0F - minimumSimilarity));
    searchTerm = term;
    field = searchTerm.field();
    
    int fullSearchTermLength = searchTerm.text().length();
    int realPrefixLength = prefixLength > fullSearchTermLength ? fullSearchTermLength : prefixLength;
    
    text = searchTerm.text().substring(realPrefixLength);
    prefix = searchTerm.text().substring(0, realPrefixLength);
    
    initializeMaxDistances();
    d = initDistanceArray();
    
    setEnum(reader.terms(new Term(searchTerm.field(), prefix)));
  }
  
  protected final boolean termCompare(Term term)
  {
    if ((field == term.field()) && (term.text().startsWith(prefix)))
    {
      String target = term.text().substring(prefix.length());
      similarity = similarity(target);
      return similarity > minimumSimilarity;
    }
    endEnum = true;
    return false;
  }
  
  public final float difference()
  {
    return (similarity - minimumSimilarity) * scale_factor;
  }
  
  public final boolean endEnum()
  {
    return endEnum;
  }
  
  private static final int min(int a, int b, int c)
  {
    int t = a < b ? a : b;
    return t < c ? t : c;
  }
  
  private final int[][] initDistanceArray()
  {
    return new int[text.length() + 1][19];
  }
  
  private float similarity(String target)
  {
    int m = target.length();
    int n = text.length();
    if (n == 0) {
      return prefix.length() == 0 ? 0.0F : 1.0F - m / prefix.length();
    }
    if (m == 0) {
      return prefix.length() == 0 ? 0.0F : 1.0F - n / prefix.length();
    }
    int maxDistance = getMaxDistance(m);
    if (maxDistance < Math.abs(m - n)) {
      return 0.0F;
    }
    if (d[0].length <= m) {
      growDistanceArray(m);
    }
    for (int i = 0; i <= n; i++) {
      d[i][0] = i;
    }
    for (int j = 0; j <= m; j++) {
      d[0][j] = j;
    }
    for (int i = 1; i <= n; i++)
    {
      int bestPossibleEditDistance = m;
      char s_i = text.charAt(i - 1);
      for (int j = 1; j <= m; j++)
      {
        if (s_i != target.charAt(j - 1)) {
          d[i][j] = (min(d[(i - 1)][j], d[i][(j - 1)], d[(i - 1)][(j - 1)]) + 1);
        } else {
          d[i][j] = min(d[(i - 1)][j] + 1, d[i][(j - 1)] + 1, d[(i - 1)][(j - 1)]);
        }
        bestPossibleEditDistance = Math.min(bestPossibleEditDistance, d[i][j]);
      }
      if ((i > maxDistance) && (bestPossibleEditDistance > maxDistance)) {
        return 0.0F;
      }
    }
    return 1.0F - d[n][m] / (prefix.length() + Math.min(n, m));
  }
  
  private void growDistanceArray(int m)
  {
    for (int i = 0; i < d.length; i++) {
      d[i] = new int[m + 1];
    }
  }
  
  private final int getMaxDistance(int m)
  {
    return m < maxDistances.length ? maxDistances[m] : calculateMaxDistance(m);
  }
  
  private void initializeMaxDistances()
  {
    for (int i = 0; i < maxDistances.length; i++) {
      maxDistances[i] = calculateMaxDistance(i);
    }
  }
  
  private int calculateMaxDistance(int m)
  {
    return (int)((1.0F - minimumSimilarity) * (Math.min(text.length(), m) + prefix.length()));
  }
  
  public void close()
    throws IOException
  {
    super.close();
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.search.FuzzyTermEnum
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.search;

import java.io.IOException;
import java.io.Serializable;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.CorruptIndexException;

/**
 * @deprecated
 */
public class Hit
  implements Serializable
{
  private Document doc = null;
  private boolean resolved = false;
  private Hits hits = null;
  private int hitNumber;
  
  Hit(Hits hits, int hitNumber)
  {
    this.hits = hits;
    this.hitNumber = hitNumber;
  }
  
  public Document getDocument()
    throws CorruptIndexException, IOException
  {
    if (!resolved) {
      fetchTheHit();
    }
    return doc;
  }
  
  public float getScore()
    throws IOException
  {
    return hits.score(hitNumber);
  }
  
  public int getId()
    throws IOException
  {
    return hits.id(hitNumber);
  }
  
  private void fetchTheHit()
    throws CorruptIndexException, IOException
  {
    doc = hits.doc(hitNumber);
    resolved = true;
  }
  
  public float getBoost()
    throws CorruptIndexException, IOException
  {
    return getDocument().getBoost();
  }
  
  public String get(String name)
    throws CorruptIndexException, IOException
  {
    return getDocument().get(name);
  }
  
  public String toString()
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append("Hit<");
    buffer.append(hits.toString());
    buffer.append(" [");
    buffer.append(hitNumber);
    buffer.append("] ");
    if (resolved) {
      buffer.append("resolved");
    } else {
      buffer.append("unresolved");
    }
    buffer.append(">");
    return buffer.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.search.Hit
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.search;

/**
 * @deprecated
 */
public abstract class HitCollector
{
  public abstract void collect(int paramInt, float paramFloat);
}

/* Location:
 * Qualified Name:     org.apache.lucene.search.HitCollector
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.search;

import java.io.IOException;
import org.apache.lucene.index.IndexReader;

/**
 * @deprecated
 */
public class HitCollectorWrapper
  extends Collector
{
  private HitCollector collector;
  private int base = 0;
  private Scorer scorer = null;
  
  public HitCollectorWrapper(HitCollector collector)
  {
    this.collector = collector;
  }
  
  public void setNextReader(IndexReader reader, int docBase)
  {
    base = docBase;
  }
  
  public void collect(int doc)
    throws IOException
  {
    collector.collect(doc + base, scorer.score());
  }
  
  public void setScorer(Scorer scorer)
    throws IOException
  {
    this.scorer = scorer;
  }
  
  public boolean acceptsDocsOutOfOrder()
  {
    return false;
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.search.HitCollectorWrapper
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.search;

import org.apache.lucene.document.Document;

final class HitDoc
{
  float score;
  int id;
  Document doc = null;
  HitDoc next;
  HitDoc prev;
  
  HitDoc(float s, int i)
  {
    score = s;
    id = i;
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.search.HitDoc
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.search;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * @deprecated
 */
public class HitIterator
  implements Iterator
{
  private Hits hits;
  private int hitNumber = 0;
  
  HitIterator(Hits hits)
  {
    this.hits = hits;
  }
  
  public boolean hasNext()
  {
    return hitNumber < hits.length();
  }
  
  public Object next()
  {
    if (hitNumber == hits.length()) {
      throw new NoSuchElementException();
    }
    Object next = new Hit(hits, hitNumber);
    hitNumber += 1;
    return next;
  }
  
  public void remove()
  {
    throw new UnsupportedOperationException();
  }
  
  public int length()
  {
    return hits.length();
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.search.HitIterator
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.search;

import org.apache.lucene.util.PriorityQueue;

final class HitQueue
  extends PriorityQueue
{
  private boolean prePopulate;
  
  HitQueue(int size, boolean prePopulate)
  {
    this.prePopulate = prePopulate;
    initialize(size);
  }
  
  protected Object getSentinelObject()
  {
    return !prePopulate ? null : new ScoreDoc(Integer.MAX_VALUE, Float.NEGATIVE_INFINITY);
  }
  
  protected final boolean lessThan(Object a, Object b)
  {
    ScoreDoc hitA = (ScoreDoc)a;
    ScoreDoc hitB = (ScoreDoc)b;
    if (score == score) {
      return doc > doc;
    }
    return score < score;
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.search.HitQueue
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.search;

import java.io.IOException;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.Vector;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexReader;

/**
 * @deprecated
 */
public final class Hits
{
  private Weight weight;
  private Searcher searcher;
  private Filter filter = null;
  private Sort sort = null;
  private int length;
  private Vector hitDocs = new Vector();
  private HitDoc first;
  private HitDoc last;
  private int numDocs = 0;
  private int maxDocs = 200;
  private int nDeletions;
  private int lengthAtStart;
  private int nDeletedHits = 0;
  boolean debugCheckedForDeletions = false;
  
  Hits(Searcher s, Query q, Filter f)
    throws IOException
  {
    weight = q.weight(s);
    searcher = s;
    filter = f;
    nDeletions = countDeletions(s);
    getMoreDocs(50);
    lengthAtStart = length;
  }
  
  Hits(Searcher s, Query q, Filter f, Sort o)
    throws IOException
  {
    weight = q.weight(s);
    searcher = s;
    filter = f;
    sort = o;
    nDeletions = countDeletions(s);
    getMoreDocs(50);
    lengthAtStart = length;
  }
  
  private int countDeletions(Searcher s)
    throws IOException
  {
    int cnt = -1;
    if ((s instanceof IndexSearcher)) {
      cnt = s.maxDoc() - ((IndexSearcher)s).getIndexReader().numDocs();
    }
    return cnt;
  }
  
  private final void getMoreDocs(int min)
    throws IOException
  {
    if (hitDocs.size() > min) {
      min = hitDocs.size();
    }
    int n = min * 2;
    TopDocs topDocs = sort == null ? searcher.search(weight, filter, n) : searcher.search(weight, filter, n, sort);
    
    length = totalHits;
    ScoreDoc[] scoreDocs = scoreDocs;
    
    float scoreNorm = 1.0F;
    if ((length > 0) && (topDocs.getMaxScore() > 1.0F)) {
      scoreNorm = 1.0F / topDocs.getMaxScore();
    }
    int start = hitDocs.size() - nDeletedHits;
    
    int nDels2 = countDeletions(searcher);
    debugCheckedForDeletions = false;
    if ((nDeletions < 0) || (nDels2 > nDeletions))
    {
      nDeletedHits = 0;
      debugCheckedForDeletions = true;
      int i2 = 0;
      for (int i1 = 0; (i1 < hitDocs.size()) && (i2 < scoreDocs.length); i1++)
      {
        int id1 = hitDocs.get(i1)).id;
        int id2 = doc;
        if (id1 == id2) {
          i2++;
        } else {
          nDeletedHits += 1;
        }
      }
      start = i2;
    }
    int end = scoreDocs.length < length ? scoreDocs.length : length;
    length += nDeletedHits;
    for (int i = start; i < end; i++) {
      hitDocs.addElement(new HitDoc(score * scoreNorm, doc));
    }
    nDeletions = nDels2;
  }
  
  public final int length()
  {
    return length;
  }
  
  public final Document doc(int n)
    throws CorruptIndexException, IOException
  {
    HitDoc hitDoc = hitDoc(n);
    
    remove(hitDoc);
    addToFront(hitDoc);
    if (numDocs > maxDocs)
    {
      HitDoc oldLast = last;
      remove(last);
      doc = null;
    }
    if (doc == null) {
      doc = searcher.doc(id);
    }
    return doc;
  }
  
  public final float score(int n)
    throws IOException
  {
    return hitDocscore;
  }
  
  public final int id(int n)
    throws IOException
  {
    return hitDocid;
  }
  
  public Iterator iterator()
  {
    return new HitIterator(this);
  }
  
  private final HitDoc hitDoc(int n)
    throws IOException
  {
    if (n >= lengthAtStart) {
      throw new IndexOutOfBoundsException("Not a valid hit number: " + n);
    }
    if (n >= hitDocs.size()) {
      getMoreDocs(n);
    }
    if (n >= length) {
      throw new ConcurrentModificationException("Not a valid hit number: " + n);
    }
    return (HitDoc)hitDocs.elementAt(n);
  }
  
  private final void addToFront(HitDoc hitDoc)
  {
    if (first == null) {
      last = hitDoc;
    } else {
      first.prev = hitDoc;
    }
    next = first;
    first = hitDoc;
    prev = null;
    
    numDocs += 1;
  }
  
  private final void remove(HitDoc hitDoc)
  {
    if (doc == null) {
      return;
    }
    if (next == null) {
      last = prev;
    } else {
      next.prev = prev;
    }
    if (prev == null) {
      first = next;
    } else {
      prev.next = next;
    }
    numDocs -= 1;
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.search.Hits
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.search;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.FieldSelector;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.ReaderUtil;

public class IndexSearcher
  extends Searcher
{
  IndexReader reader;
  private boolean closeReader;
  private IndexReader[] subReaders;
  private int[] docStarts;
  private boolean fieldSortDoTrackScores;
  private boolean fieldSortDoMaxScore;
  
  /**
   * @deprecated
   */
  public IndexSearcher(String path)
    throws CorruptIndexException, IOException
  {
    this(IndexReader.open(path), true);
  }
  
  /**
   * @deprecated
   */
  public IndexSearcher(String path, boolean readOnly)
    throws CorruptIndexException, IOException
  {
    this(IndexReader.open(path, readOnly), true);
  }
  
  /**
   * @deprecated
   */
  public IndexSearcher(Directory directory)
    throws CorruptIndexException, IOException
  {
    this(IndexReader.open(directory), true);
  }
  
  public IndexSearcher(Directory path, boolean readOnly)
    throws CorruptIndexException, IOException
  {
    this(IndexReader.open(path, readOnly), true);
  }
  
  public IndexSearcher(IndexReader r)
  {
    this(r, false);
  }
  
  private IndexSearcher(IndexReader r, boolean closeReader)
  {
    reader = r;
    this.closeReader = closeReader;
    
    List subReadersList = new ArrayList();
    gatherSubReaders(subReadersList, reader);
    subReaders = ((IndexReader[])subReadersList.toArray(new IndexReader[subReadersList.size()]));
    docStarts = new int[subReaders.length];
    int maxDoc = 0;
    for (int i = 0; i < subReaders.length; i++)
    {
      docStarts[i] = maxDoc;
      maxDoc += subReaders[i].maxDoc();
    }
  }
  
  protected void gatherSubReaders(List allSubReaders, IndexReader r)
  {
    ReaderUtil.gatherSubReaders(allSubReaders, r);
  }
  
  public IndexReader getIndexReader()
  {
    return reader;
  }
  
  public void close()
    throws IOException
  {
    if (closeReader) {
      reader.close();
    }
  }
  
  public int docFreq(Term term)
    throws IOException
  {
    return reader.docFreq(term);
  }
  
  public Document doc(int i)
    throws CorruptIndexException, IOException
  {
    return reader.document(i);
  }
  
  public Document doc(int i, FieldSelector fieldSelector)
    throws CorruptIndexException, IOException
  {
    return reader.document(i, fieldSelector);
  }
  
  public int maxDoc()
    throws IOException
  {
    return reader.maxDoc();
  }
  
  public TopDocs search(Weight weight, Filter filter, int nDocs)
    throws IOException
  {
    if (nDocs <= 0) {
      throw new IllegalArgumentException("nDocs must be > 0");
    }
    nDocs = Math.min(nDocs, reader.maxDoc());
    
    TopScoreDocCollector collector = TopScoreDocCollector.create(nDocs, !weight.scoresDocsOutOfOrder());
    search(weight, filter, collector);
    return collector.topDocs();
  }
  
  public TopFieldDocs search(Weight weight, Filter filter, int nDocs, Sort sort)
    throws IOException
  {
    return search(weight, filter, nDocs, sort, true);
  }
  
  public TopFieldDocs search(Weight weight, Filter filter, int nDocs, Sort sort, boolean fillFields)
    throws IOException
  {
    nDocs = Math.min(nDocs, reader.maxDoc());
    
    SortField[] fields = fields;
    boolean legacy = false;
    for (int i = 0; i < fields.length; i++)
    {
      SortField field = fields[i];
      String fieldname = field.getField();
      int type = field.getType();
      if (type == 2)
      {
        int autotype = SortField.detectFieldType(reader, fieldname);
        if (autotype == 3) {
          fields[i] = new SortField(fieldname, field.getLocale(), field.getReverse());
        } else {
          fields[i] = new SortField(fieldname, autotype, field.getReverse());
        }
      }
      if (field.getUseLegacySearch()) {
        legacy = true;
      }
    }
    if (legacy)
    {
      TopDocCollector collector = new TopFieldDocCollector(reader, sort, nDocs);
      HitCollectorWrapper hcw = new HitCollectorWrapper(collector);
      hcw.setNextReader(reader, 0);
      if (filter == null)
      {
        Scorer scorer = weight.scorer(reader, true, true);
        if (scorer != null) {
          scorer.score(hcw);
        }
      }
      else
      {
        searchWithFilter(reader, weight, filter, hcw);
      }
      return (TopFieldDocs)collector.topDocs();
    }
    TopFieldCollector collector = TopFieldCollector.create(sort, nDocs, fillFields, fieldSortDoTrackScores, fieldSortDoMaxScore, !weight.scoresDocsOutOfOrder());
    
    search(weight, filter, collector);
    return (TopFieldDocs)collector.topDocs();
  }
  
  public void search(Weight weight, Filter filter, Collector collector)
    throws IOException
  {
    if (filter == null) {
      for (int i = 0; i < subReaders.length; i++)
      {
        collector.setNextReader(subReaders[i], docStarts[i]);
        Scorer scorer = weight.scorer(subReaders[i], !collector.acceptsDocsOutOfOrder(), true);
        if (scorer != null) {
          scorer.score(collector);
        }
      }
    } else {
      for (int i = 0; i < subReaders.length; i++)
      {
        collector.setNextReader(subReaders[i], docStarts[i]);
        searchWithFilter(subReaders[i], weight, filter, collector);
      }
    }
  }
  
  private void searchWithFilter(IndexReader reader, Weight weight, Filter filter, Collector collector)
    throws IOException
  {
    assert (filter != null);
    
    Scorer scorer = weight.scorer(reader, true, false);
    if (scorer == null) {
      return;
    }
    int docID = scorer.docID();
    assert ((docID == -1) || (docID == Integer.MAX_VALUE));
    
    DocIdSet filterDocIdSet = filter.getDocIdSet(reader);
    if (filterDocIdSet == null) {
      return;
    }
    DocIdSetIterator filterIter = filterDocIdSet.iterator();
    if (filterIter == null) {
      return;
    }
    int filterDoc = filterIter.nextDoc();
    int scorerDoc = scorer.advance(filterDoc);
    
    collector.setScorer(scorer);
    for (;;)
    {
      if (scorerDoc == filterDoc)
      {
        if (scorerDoc == Integer.MAX_VALUE) {
          break;
        }
        collector.collect(scorerDoc);
        filterDoc = filterIter.nextDoc();
        scorerDoc = scorer.advance(filterDoc);
      }
      else if (scorerDoc > filterDoc)
      {
        filterDoc = filterIter.advance(scorerDoc);
      }
      else
      {
        scorerDoc = scorer.advance(filterDoc);
      }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd