Lucy::...utorial(3pm)
π Lucy::Docs::Tutorial::FieldTypeTutorial π
okay bestie, so this one lives in the Lucy::...utorial(3pm) corner of the User Contributed Perl Documentation universe, and it's literally about giving each field its own lil personality. no cap.
β¨ NAME β¨
Lucy::Docs::Tutorial::FieldTypeTutorial β specify per-field properties and behaviors. yes, per-field. every field gets to be its own main character. π
πΈ DESCRIPTION πΈ
so the Schema we built in the last chapter specifies three fields, right? here's the whole vibe:
my $type = Lucy::Plan::FullTextType->new(
analyzer => $easyanalyzer,
);
$schema->spec_field( name => 'title', type => $type );
$schema->spec_field( name => 'content', type => $type );
$schema->spec_field( name => 'url', type => $type );
and because all three of them are defined as βfull textβ fields, they're all searchable β including the "url" field, which is honestly a dubious choice. π like, some URLs do carry meaningful info, but these ones? these ones really don't:
http://example.com/us_constitution/amend1.txt
it's giving nothing. so we may as well not bother indexing the URL content at all. and to make that happen, we gotta assign the "url" field to a different FieldType. slay.
π§΅ StringType π§΅
so instead of FullTextType, we're gonna use a StringType. the difference? a StringType doesn't use an Analyzer to break up text into individual fields. and not only that β we're marking this StringType as unindexed, so its content won't be searchable at all. zero. nada. π
my $url_type = Lucy::Plan::StringType->new( indexed => 0 );
$schema->spec_field( name => 'url', type => $url_type );
wanna observe the change in behavior with your own two eyes? try searching for "us_constitution" both before and after changing the Schema and re-indexing. it's a whole before/after glow-up moment, fr fr. β¨
π Toggling βstoredβ π
for a lil taste of what else FieldType can do, try turning off "stored" for one or more fields. go wild.
my $content_type = Lucy::Plan::FullTextType->new(
analyzer => $easyanalyzer,
stored => 0,
);
so here's the tea: turning off "stored" for either "title" or "url" mangles our results page π (do not recommend), but since we're not actually displaying "content" anywhere, turning it off for "content" has no effect β except on index size. tiny win, we'll take it. π«Ά
π Analyzers up next π
Analyzers play a crucial role in the behavior of FullTextType fields. like, they're the whole vibe honestly. in our next tutorial chapter, AnalysisTutorial, we'll see how changing up the Analyzer changes search results. π
and that's the whole page, bestie!! π¦ this was Lucy::...utorial(3pm) from perl v5.42.0, dated 2025-07-25 β mwah, iconic, 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