Lucy::...utorial(3pm)

πŸ“¦
version 0.6.2 Β· 2 versions
, in fedora 43

πŸ’– 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