Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.lucene.misc
Class SweetSpotSimilarity

    java.lang.Object
      org.apache.lucene.search.Similarity
          org.apache.lucene.search.DefaultSimilarity
              org.apache.lucene.misc.SweetSpotSimilarity

All Implemented Interfaces:
  Serializable

    public class SweetSpotSimilarity

extends DefaultSimilarity

A similarity with a lengthNorm that provides for a "platuea" of equally good lengths, and tf helper functions.

For lengthNorm, A global min/max can be specified to define the platuea of lengths that should all have a norm of 1.0. Below the min, and above the max the lengthNorm drops off in a sqrt function.

A per field min/max can be specified if different fields have different sweet spots.

For tf, baselineTf and hyperbolicTf functions are provided, which subclasses can choose between.

See Also:
  Serialized Form

Constructor Summary
`SweetSpotSimilarity()`

Method Summary
`float` | `baselineTf(float freq)` Implemented as: `(x <= min) ? base : sqrt(x+(base**2)-min)` ...but with a special case check for 0.
`float` | `hyperbolicTf(float freq)` Uses a hyperbolic tangent function that allows for a hard max...
`float` | `lengthNorm(String fieldName, int numTerms)` Implemented as: `1/sqrt( steepness * (abs(x-min) + abs(x-max) - (max-min)) + 1 )` .
`void` | `setBaselineTfFactors(float base, float min)` Sets the baseline and minimum function variables for baselineTf
`void` | `setHyperbolicTfFactors(float min, float max, double base, float xoffset)` Sets the function variables for the hyperbolicTf functions
`void` | `setLengthNormFactors(int min, int max, float steepness)` Sets the default function variables used by lengthNorm when no field specifc variables have been set.
`void` | `setLengthNormFactors(String field, int min, int max, float steepness)` Sets the function variables used by lengthNorm for a specific named field
`float` | `tf(int freq)` Delegates to baselineTf

Methods inherited from class org.apache.lucene.search.DefaultSimilarity
`coord, idf, queryNorm, sloppyFreq, tf`

Methods inherited from class org.apache.lucene.search.Similarity
`decodeNorm, encodeNorm, getDefault, getNormDecoder, idf, idf, scorePayload, setDefault`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### SweetSpotSimilarity

    public SweetSpotSimilarity()

Method Detail

### setBaselineTfFactors

    public void setBaselineTfFactors(float base,
                                     float min)

  Sets the baseline and minimum function variables for baselineTf

  See Also:
    `baselineTf(float)`

### setHyperbolicTfFactors

    public void setHyperbolicTfFactors(float min,
                                       float max,
                                       double base,
                                       float xoffset)

  Sets the function variables for the hyperbolicTf functions

  Parameters:
    `min` - the minimum tf value to ever be returned (default: 0.0)
    `max` - the maximum tf value to ever be returned (default: 2.0)
    `base` - the base value to be used in the exponential for the hyperbolic function (default: e)
    `xoffset` - the midpoint of the hyperbolic function (default: 10.0)
  See Also:
    `hyperbolicTf(float)`

### setLengthNormFactors

    public void setLengthNormFactors(int min,
                                     int max,
                                     float steepness)

  Sets the default function variables used by lengthNorm when no field specifc variables have been set.

  See Also:
    `lengthNorm(java.lang.String, int)`

### setLengthNormFactors

    public void setLengthNormFactors(String field,
                                     int min,
                                     int max,
                                     float steepness)

  Sets the function variables used by lengthNorm for a specific named field

  See Also:
    `lengthNorm(java.lang.String, int)`

### lengthNorm

    public float lengthNorm(String fieldName,
                            int numTerms)

  Implemented as: `1/sqrt( steepness * (abs(x-min) + abs(x-max) - (max-min)) + 1 )` .

  This degrades to `1/sqrt(x)` when min and max are both 1 and steepness is 0.5

  :TODO: potential optimiation is to just flat out return 1.0f if numTerms is between min and max.

  Overrides:
    `lengthNorm` in class `DefaultSimilarity`
  Parameters:
    `fieldName` - the name of the field
    `numTerms` - the total number of tokens contained in fields named fieldName of doc.
  Returns:
    a normalization factor for hits on this field of this document
  See Also:
    `setLengthNormFactors(int, int, float)`

### tf

    public float tf(int freq)

  Delegates to baselineTf

  Overrides:
    `tf` in class `Similarity`
  Parameters:
    `freq` - the frequency of a term within a document
  Returns:
    a score factor based on a term's within-document frequency
  See Also:
    `baselineTf(float)`

### baselineTf

    public float baselineTf(float freq)

  Implemented as: `(x <= min) ? base : sqrt(x+(base**2)-min)` ...but with a special case check for 0.

  This degrates to `sqrt(x)` when min and base are both 0

  See Also:
    `setBaselineTfFactors(float, float)`

### hyperbolicTf

    public float hyperbolicTf(float freq)

  Uses a hyperbolic tangent function that allows for a hard max... `tf(x)=min+(max-min)/2*(((base**(x-xoffset)-base**-(x-xoffset))/(base**(x-xoffset)+base**-(x-xoffset)))+1)`

  This code is provided as a convincience for subclasses that want to use a hyperbolic tf function.

  See Also:
    `setHyperbolicTfFactors(float, float, double, float)`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2009 Apache Software Foundation. All Rights Reserved.