lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject cvs commit: jakarta-lucene/src/java/org/apache/lucene/search/spans SpanWeight.java
Date Fri, 06 Feb 2004 19:19:20 GMT
cutting     2004/02/06 11:19:20

  Modified:    .        CHANGES.txt
               src/java/org/apache/lucene/search BooleanQuery.java
                        PhrasePrefixQuery.java PhraseQuery.java Query.java
                        TermQuery.java
               src/java/org/apache/lucene/search/spans SpanWeight.java
  Log:
  Permit queries to override the Similarity implementation.
  
  Revision  Changes    Path
  1.70      +6 -1      jakarta-lucene/CHANGES.txt
  
  Index: CHANGES.txt
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/CHANGES.txt,v
  retrieving revision 1.69
  retrieving revision 1.70
  diff -u -r1.69 -r1.70
  --- CHANGES.txt	30 Jan 2004 22:09:59 -0000	1.69
  +++ CHANGES.txt	6 Feb 2004 19:19:20 -0000	1.70
  @@ -45,6 +45,11 @@
    7. Added a new span-based query API.  This implements, among other
       things, nested phrases.  See javadocs for details.  (Doug Cutting)
   
  + 8. Added new method Query.getSimilarity(Searcher), and changed
  +    scorers to use it.  This permits one to subclass a Query class so
  +    that it can specify it's own Similarity implementation, perhaps
  +    one that delegates through that of the Searcher.
  +
   
   1.3 final
   
  
  
  
  1.19      +3 -3      jakarta-lucene/src/java/org/apache/lucene/search/BooleanQuery.java
  
  Index: BooleanQuery.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/search/BooleanQuery.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- BooleanQuery.java	15 Jan 2004 22:42:32 -0000	1.18
  +++ BooleanQuery.java	6 Feb 2004 19:19:20 -0000	1.19
  @@ -176,7 +176,7 @@
   
         if (allRequired && noneBoolean) {           // ConjunctionScorer is okay
           ConjunctionScorer result =
  -          new ConjunctionScorer(searcher.getSimilarity());
  +          new ConjunctionScorer(getSimilarity(searcher));
           for (int i = 0 ; i < weights.size(); i++) {
             BooleanClause c = (BooleanClause)clauses.elementAt(i);
             Weight w = (Weight)weights.elementAt(i);
  @@ -189,7 +189,7 @@
         }
   
         // Use good-old BooleanScorer instead.
  -      BooleanScorer result = new BooleanScorer(searcher.getSimilarity());
  +      BooleanScorer result = new BooleanScorer(getSimilarity(searcher));
   
         for (int i = 0 ; i < weights.size(); i++) {
           BooleanClause c = (BooleanClause)clauses.elementAt(i);
  @@ -233,7 +233,7 @@
         if (coord == 1)                               // only one clause matched
           sumExpl = sumExpl.getDetails()[0];          // eliminate wrapper
   
  -      float coordFactor = searcher.getSimilarity().coord(coord, maxCoord);
  +      float coordFactor = getSimilarity(searcher).coord(coord, maxCoord);
         if (coordFactor == 1.0f)                      // coord is no-op
           return sumExpl;                             // eliminate wrapper
         else {
  
  
  
  1.11      +3 -3      jakarta-lucene/src/java/org/apache/lucene/search/PhrasePrefixQuery.java
  
  Index: PhrasePrefixQuery.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/search/PhrasePrefixQuery.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- PhrasePrefixQuery.java	15 Dec 2003 22:26:13 -0000	1.10
  +++ PhrasePrefixQuery.java	6 Feb 2004 19:19:20 -0000	1.11
  @@ -135,7 +135,7 @@
         while (i.hasNext()) {
           Term[] terms = (Term[])i.next();
           for (int j=0; j<terms.length; j++)
  -          idf += searcher.getSimilarity().idf(terms[j], searcher);
  +          idf += getSimilarity(searcher).idf(terms[j], searcher);
         }
   
         queryWeight = idf * getBoost();             // compute query weight
  @@ -169,10 +169,10 @@
         }
       
         if (slop == 0)
  -        return new ExactPhraseScorer(this, tps, searcher.getSimilarity(),
  +        return new ExactPhraseScorer(this, tps, getSimilarity(searcher),
                                        reader.norms(field));
         else
  -        return new SloppyPhraseScorer(this, tps, searcher.getSimilarity(),
  +        return new SloppyPhraseScorer(this, tps, getSimilarity(searcher),
                                         slop, reader.norms(field));
       }
       
  
  
  
  1.13      +3 -3      jakarta-lucene/src/java/org/apache/lucene/search/PhraseQuery.java
  
  Index: PhraseQuery.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/search/PhraseQuery.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PhraseQuery.java	15 Dec 2003 22:26:13 -0000	1.12
  +++ PhraseQuery.java	6 Feb 2004 19:19:20 -0000	1.13
  @@ -121,7 +121,7 @@
       public float getValue() { return value; }
   
       public float sumOfSquaredWeights() throws IOException {
  -      idf = searcher.getSimilarity().idf(terms, searcher);
  +      idf = getSimilarity(searcher).idf(terms, searcher);
         queryWeight = idf * getBoost();             // compute query weight
         return queryWeight * queryWeight;           // square it
       }
  @@ -145,11 +145,11 @@
         }
   
         if (slop == 0)				  // optimize exact case
  -        return new ExactPhraseScorer(this, tps, searcher.getSimilarity(),
  +        return new ExactPhraseScorer(this, tps, getSimilarity(searcher),
                                        reader.norms(field));
         else
           return
  -          new SloppyPhraseScorer(this, tps, searcher.getSimilarity(), slop,
  +          new SloppyPhraseScorer(this, tps, getSimilarity(searcher), slop,
                                    reader.norms(field));
         
       }
  
  
  
  1.14      +10 -1     jakarta-lucene/src/java/org/apache/lucene/search/Query.java
  
  Index: Query.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/search/Query.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Query.java	3 Oct 2003 03:05:28 -0000	1.13
  +++ Query.java	6 Feb 2004 19:19:20 -0000	1.14
  @@ -120,7 +120,7 @@
       Query query = searcher.rewrite(this);
       Weight weight = query.createWeight(searcher);
       float sum = weight.sumOfSquaredWeights();
  -    float norm = searcher.getSimilarity().queryNorm(sum);
  +    float norm = getSimilarity(searcher).queryNorm(sum);
       weight.normalize(norm);
       return weight;
     }
  @@ -161,6 +161,15 @@
       }
       return result;
     }
  +
  +  /** Expert: Returns the Similarity implementation to be used for this query.
  +   * Subclasses may override this method to specify their own Similarity
  +   * implementation, perhaps one that delegates through that of the Searcher.
  +   * By default the Searcher's Similarity implementation is returned.*/
  +  public Similarity getSimilarity(Searcher searcher) {
  +    return searcher.getSimilarity();
  +  }
  +
   
   
     /** Returns a clone of this query. */
  
  
  
  1.9       +2 -2      jakarta-lucene/src/java/org/apache/lucene/search/TermQuery.java
  
  Index: TermQuery.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/search/TermQuery.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TermQuery.java	15 Dec 2003 22:26:13 -0000	1.8
  +++ TermQuery.java	6 Feb 2004 19:19:20 -0000	1.9
  @@ -80,7 +80,7 @@
       public float getValue() { return value; }
   
       public float sumOfSquaredWeights() throws IOException {
  -      idf = searcher.getSimilarity().idf(term, searcher); // compute idf
  +      idf = getSimilarity(searcher).idf(term, searcher); // compute idf
         queryWeight = idf * getBoost();             // compute query weight
         return queryWeight * queryWeight;           // square it
       }
  @@ -97,7 +97,7 @@
         if (termDocs == null)
           return null;
         
  -      return new TermScorer(this, termDocs, searcher.getSimilarity(),
  +      return new TermScorer(this, termDocs, getSimilarity(searcher),
                               reader.norms(term.field()));
       }
   
  
  
  
  1.3       +2 -2      jakarta-lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java
  
  Index: SpanWeight.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SpanWeight.java	2 Feb 2004 13:27:52 -0000	1.2
  +++ SpanWeight.java	6 Feb 2004 19:19:20 -0000	1.3
  @@ -51,7 +51,7 @@
     public float getValue() { return value; }
   
     public float sumOfSquaredWeights() throws IOException {
  -    idf = searcher.getSimilarity().idf(terms, searcher);
  +    idf = this.query.getSimilarity(searcher).idf(terms, searcher);
       queryWeight = idf * query.getBoost();         // compute query weight
       return queryWeight * queryWeight;             // square it
     }
  @@ -64,7 +64,7 @@
   
     public Scorer scorer(IndexReader reader) throws IOException {
       return new SpanScorer(query.getSpans(reader), this,
  -                          searcher.getSimilarity(),
  +                          query.getSimilarity(searcher),
                             reader.norms(query.getField()));
     }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message