Lucy::...ilarity(3pm)
β¨ Lucy::Index::Similarity β¨
okay so bestie, welcome to Lucy::Index::Similarity π β the manual page you're reading is filed under Lucy::...ilarity(3pm), part of the User Contributed Perl Documentation collection (iykyk, the truncation is just the man page being dramatic π).
πΈ NAME πΈ
Lucy::Index::Similarity β judge how well a document matches a query. that's it. that's the job. π
π¦ SYNOPSIS π¦
package MySimilarity;
sub length_norm { return 1.0 } # disable length normalization
package MyFullTextType;
use base qw( Lucy::Plan::FullTextType );
sub make_similarity { MySimilarity->new }
π DESCRIPTION π
So here's the tea, bestie: once we've figured out whether a document matches a given query, we still have to calculate a score that says how well it matches. that's literally the whole point of the Similarity class β it judges how "similar" the query and the document are to each other. the closer the resemblance, the higher the document scores. periodt. π
The default implementation uses Lucene's modified cosine similarity measure β¨. Subclasses might tweak the existing algorithms, or might be used in conjunction with custom Query subclasses to implement arbitrary scoring schemes β like, go off, invent your own scoring vibe π.
Most of the methods operate on single fields, but some are used to combine scores from multiple fields. both vibes exist, we contain multitudes π.
π CONSTRUCTORS π
π« new
my $sim = Lucy::Index::Similarity->new;
Constructor. Takes no arguments. zero. none. she simply is π§β¨.
π METHODS π
π length_norm
my $float = $similarity->length_norm($num_tokens);
Dampen the scores of long documents π«Ά.
After a field is broken up into terms at index-time, each term must be assigned a weight. One of the factors in calculating this weight is the number of tokens that the original field was broken into. that's the mechanics, no cap.
Typically, we assume that the more tokens in a field, the less important any one of them is β so that, e.g. 5 mentions of "Kafka" in a short article are given more heft than 5 mentions of "Kafka" in an entire book π. like yeah, obviously, the short article is about Kafka. the default implementation of length_norm expresses this using an inverted square root β¨.
However β and this is the important caveat, don't skip it β the inverted square root has a tendency to reward very short fields highly, which isn't always appropriate for fields you expect to have a lot of tokens on average. so, y'know, vibe check your field before you commit π.
π INHERITANCE π
Lucy::Index::Similarity isa Clownfish::Obj. family tree confirmed, ancestors slay πΈ.
perl v5.42.0 π 2025-07-25 β that's the source, the version, and the date, bestie, all wrapped up in a little bow. thanks for reading the whole thing, you ate π β¨π¦
π¦ where this page comes from
- fedora 43: perl-Lucy 0.6.2-26.fc43 Β· Apache-2.0 AND MIT AND Unicode-DFS-2015
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms