12
Using SweetSpotSimilarity for Solr Fulltext Indexing (A Public Service Message) Jay Luker SAO/NASA Astrophysics Data System http://adsabs.harvard.edu/

Using SweetSpotSimilarity for Solr Fulltext Indexing

Embed Size (px)

DESCRIPTION

From a code4lib online lightning talk in 04/2011.

Citation preview

Page 1: Using SweetSpotSimilarity for Solr Fulltext Indexing

Using SweetSpotSimilarity for Solr Fulltext Indexing

(A Public Service Message)

Jay LukerSAO/NASA Astrophysics Data System

http://adsabs.harvard.edu/

Page 2: Using SweetSpotSimilarity for Solr Fulltext Indexing

From http://lucene.apache.org/java/2_9_3/api/all/org/apache/lucene/search/Similarity.html

Score for a particular

result

Buncha stuff you probably ought to read up on.

"encapsulates a few (indexing

time) boost and length factors"

{

Page 3: Using SweetSpotSimilarity for Solr Fulltext Indexing

norm(t,d)

Includes... ● Document boost - e.g. <doc boost="2.5"> ● Field boost - e.g. <field boost="3.0">

and what we're concerned with...

● lengthNorm(field) - computed at index time based on the number of tokens in the field of the input document.

These factors, multiplied together, make up the norm(t,d) for a given document

Page 4: Using SweetSpotSimilarity for Solr Fulltext Indexing

lengthNorm(String fieldName, int numTokens)"Matches in longer fields are less precise, so implementations of this method usually return smaller values when numTokens is large, and larger values when numTokens is small."

Translation:

SHORTER DOCUMENTS SCORE HIGHER

from the javadoc:

Page 5: Using SweetSpotSimilarity for Solr Fulltext Indexing

changes this ...

to this ...

lengthNorm(L) = 1

sqrt(L)

SweetSpotSimilarity

lucene/contrib/misc/...

lengthNorm(L) =1

sqrt(steepness*(|L-min|+|L-max|-(max-min))+1)

Page 6: Using SweetSpotSimilarity for Solr Fulltext Indexing

min/max = your "sweet spot" range. Lengths within this range compute to a constant, i.e., 1. steepness = controls the curve up to and down from the sweet spot "plateau".

Page 7: Using SweetSpotSimilarity for Solr Fulltext Indexing

(termcounts for all ADS's searchable fulltext since 01/2000)

Page 8: Using SweetSpotSimilarity for Solr Fulltext Indexing

<similarity class="org.ads.solr.SweetSpotSimilarityFactory"> <str name="min">1000</str> <str name="max">20000</str> <str name="steepness">0.5</str> </similarity>

In schema.xml

Page 9: Using SweetSpotSimilarity for Solr Fulltext Indexing

public class SweetSpotSimilarityFactory extends SimilarityFactory {

public static final Logger log = \ LoggerFactory.getLogger(SolrResourceLoader.class);

@Override public Similarity getSimilarity() { SweetSpotSimilarity sim = new SweetSpotSimilarity();

int max = this.params.getInt("max"); int min = this.params.getInt("min"); float steepness = this.params.getFloat("steepness");

log.info("max: " + max); log.info("min: " + min); log.info("steepness: " + steepness);

// yuck! hardcoded field settings for now sim.setLengthNormFactors("body", min, max, steepness, true); return sim; }}

Page 10: Using SweetSpotSimilarity for Solr Fulltext Indexing
Page 11: Using SweetSpotSimilarity for Solr Fulltext Indexing
Page 12: Using SweetSpotSimilarity for Solr Fulltext Indexing

Thanks!

Further reading: "Lucene and Juru at TREC 2007: 1-Million Queries Track"

http://trec.nist.gov/pubs/trec16/papers/ibm-haifa.mq.final.pdf

Also, check out our Blacklight beta search!http://labs.adsabs.harvard.edu/fulltext