Lucy::...torial(3pm)
π NAME π
Lucy::Docs::Tutorial::AnalysisTutorial β like, how do you even choose an Analyzer, and then how do you use it?? bestie we're about to find out β¨
(this whole thing lives in the Lucy::...torial(3pm) manual, for the record π)
πΈ DESCRIPTION πΈ
okay so first mission: go swap out the EasyAnalyzer in our Schema for a StandardTokenizer. just. try it. be brave π
my $tokenizer = Lucy::Analysis::StandardTokenizer->new;
my $type = Lucy::Plan::FullTextType->new(
analyzer => $tokenizer,
);
Now search for "senate", "Senate", and "Senator" β do it before AND after you make the change and re-index. the difference is gonna gag you fr fr π
Under EasyAnalyzer, all three searches give you identical results. cute, consistent, predictable. but under StandardTokenizer? searches become case-sensitive, and the result sets for "Senate" and "Senator" are distinct. not the same thing anymore, not even close π
β¨ EasyAnalyzer β¨
so what's actually happening here? EasyAnalyzer is doing WAY more aggressive processing than StandardTokenizer. like, it's not just tokenizing β it's also:
- converting all text to lower case, so searches are case-insensitive (yes ma'am, lowercase everything π)
- running a "stemming" algorithm to squish related words down to a common stem (
"senat", in this case) π¦
EasyAnalyzer is actually multiple Analyzers wrapped up in one single package. in this case it's a three-in-one situation, because specifying an EasyAnalyzer with "language => 'en'" is equivalent to this snippet creating a PolyAnalyzer:
my $tokenizer = Lucy::Analysis::StandardTokenizer->new;
my $normalizer = Lucy::Analysis::Normalizer->new;
my $stemmer = Lucy::Analysis::SnowballStemmer->new( language => 'en' );
my $polyanalyzer = Lucy::Analysis::PolyAnalyzer->new(
analyzers => [ $tokenizer, $normalizer, $stemmer ],
);
and you can add or subtract Analyzers from there if you feel like it, no cap. try adding a fourth Analyzer β a SnowballStopFilter for suppressing "stopwords" like "the", "if", and "maybe" π
my $stopfilter = Lucy::Analysis::SnowballStopFilter->new(
language => 'en',
);
my $polyanalyzer = Lucy::Analysis::PolyAnalyzer->new(
analyzers => [ $tokenizer, $normalizer, $stopfilter, $stemmer ],
);
also β try removing the SnowballStemmer. just for the plot π
my $polyanalyzer = Lucy::Analysis::PolyAnalyzer->new(
analyzers => [ $tokenizer, $normalizer ],
);
ngl, the original choice of a stock English EasyAnalyzer probably still yields the best results for this document collection. but you get the idea, bestie: sometimes you just want a different Analyzer. it's giving β¨customizationβ¨
π When the best Analyzer is no Analyzer π
sometimes you don't want an Analyzer at all. that was true for our "url" field because we didn't need it to be searchable β but it's also true for certain types of searchable fields. for instance, "category" fields are often set up to match exactly or not at all, and so are fields like "last_name" (because you may not want to conflate results for "Humphrey" and "Humphries" β those are two different people, okay?? π€).
to specify that there should be no analysis performed at all, use StringType:
my $type = Lucy::Plan::StringType->new;
$schema->spec_field( name => 'category', type => $type );
lowkey the vibe here is: sometimes the best glow-up is no glow-up π
π Highlighting up next π
in our next tutorial chapter, HighlighterTutorial, we'll add highlighted excerpts from the "content" field to our search results. main character energy incoming, you're not ready π₯
and that's the tea, bestie π«Ά this page came to you from perl v5.42.0, dated 2025-07-25 β go forth and analyze, periodt πβ¨
π¦ 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