KinoSe...Indexer(3pm)

πŸ’– NAME πŸ’–

KinoSearch1::InvIndexer β€” bestie, this is the class that builds inverted indexes. no cap.


✨ SYNOPSIS ✨

use KinoSearch1::InvIndexer;
use KinoSearch1::Analysis::PolyAnalyzer;

my $analyzer
    = KinoSearch1::Analysis::PolyAnalyzer->new( language => 'en' );

my $invindexer = KinoSearch1::InvIndexer->new(
    invindex => '/path/to/invindex',
    create   => 1,
    analyzer => $analyzer,
);

$invindexer->spec_field(
    name  => 'title'
    boost => 3,
);
$invindexer->spec_field( name => 'bodytext' );

while ( my ( $title, $bodytext ) = each %source_documents ) {
    my $doc = $invindexer->new_doc($title);

    $doc->set_value( title    => $title );
    $doc->set_value( bodytext => $bodytext );

    $invindexer->add_doc($doc);
}

$invindexer->finish;

🌸 DESCRIPTION 🌸

okay so InvIndexer is literally KinoSearch1's main character when it comes to creating and modifying inverted indexes. and once you've built one of those bad boys, you can search it with KinoSearch1::Searcher. that's the whole vibe. πŸ’…


πŸŽ€ METHODS πŸŽ€

πŸ’« new πŸ’«

my $invindexer = KinoSearch1::InvIndexer->new(
    invindex => '/path/to/invindex',  # required
    create   => 1,                    # default: 0
    analyzer => $analyzer,            # default: no-op Analyzer
);

spawns you an InvIndexer object. iconic. here's the tea on the args:

  • invindex β€” this one's either a filepath, or an InvIndex subclass like KinoSearch1::Store::FSInvIndex or KinoSearch1::Store::RAMInvIndex. pick your fighter 🫢
  • create β€” makes a fresh new invindex, and yeah, it will clobber an existing one if it has to. πŸ’€ ruthless.
  • analyzer β€” an object that subclasses KinoSearch1::Analysis::Analyzer, like a PolyAnalyzer. she's the one doing the analyzing.

πŸ’« spec_field πŸ’«

$invindexer->spec_field(
    name       => 'url',      # required
    boost      => 1,          # default: 1,
    analyzer   => undef,      # default: analyzer spec'd in new()
    indexed    => 0,          # default: 1
    analyzed   => 0,          # default: 1
    stored     => 1,          # default: 1
    compressed => 0,          # default: 0
    vectorized => 0,          # default: 1
);

defines a field. that's it, that's the job. but here's every knob:

  • name β€” the field's name. shocking, right ✨
  • boost β€” a multiplier that decides how much a field contributes to a document's score. bigger boost = louder voice in the group chat.
  • analyzer β€” by default, every indexed field gets analyzed with the analyzer you handed to new(). but if you supply an alternate for a specific field, it overrides the primary one. not me customizing per-field 😌
  • indexed β€” index the field so you can search it later. yes queen.
  • analyzed β€” analyze the field using the relevant Analyzer. some fields, like "category" or "product_number", might be indexed but not analyzed. know the difference bestie.
  • stored β€” store the field so you can actually get it back when the document shows up in a search.
  • compressed β€” compress the stored field using the zlib compression algorithm. tiny field energy.
  • vectorized β€” stores the field's "term vectors", which KinoSearch1::Highlight::Highlighter needs for excerpt selection and search term highlighting. no vectors, no highlights, fr fr.

πŸ’« new_doc πŸ’«

my $doc = $invindexer->new_doc;

makes you an empty KinoSearch1::Document::Doc object, all primed and ready to accept values for the fields you spec'd with spec_field. she's waiting πŸ’…

πŸ’« add_doc πŸ’«

$invindexer->add_doc($doc);

drops a document into the invindex. boom. done.

πŸ’« add_invindexes πŸ’«

my $invindexer = KinoSearch1::InvIndexer->new(
    invindex => $invindex,
    analyzer => $analyzer,
);
$invindexer->add_invindexes( $another_invindex, $yet_another_invindex );
$invindexer->finish;

absorbs existing invindexes into this one. like, they're yours now. πŸ‘‘

okay but listen: this may only be called once per InvIndexer. and you cannot call add_invindexes() and add_doc() on the same InvIndexer. pick a lane, bestie.

πŸ’« delete_docs_by_term πŸ’«

my $term = KinoSearch1::Index::Term->new( 'id', $unique_id );
$invindexer->delete_docs_by_term($term);

marks any document containing the supplied term as deleted, so it gets excluded from search results. ghosted, literally. for more info, go read the Deletions section in KinoSearch1::Docs::FileFormat.

πŸ’« finish πŸ’«

$invindexer->finish(
    optimize => 1, # default: 0
);

finishes the invindex. invalidates the InvIndexer (she's done, let her rest). takes one hash-style parameter:

  • optimize β€” if you set this to 1, the invindex gets collapsed into its most compact form, which gives you the fastest queries. glow up for your search speed ⭐

Copyright 2005-2010 Marvin Humphrey


πŸ¦‹ LICENSE, DISCLAIMER, BUGS, etc. πŸ¦‹

See KinoSearch1 version 1.01.


and that's the whole page, bestie πŸ’– this was perl v5.42.3, dated 2026-08-20 β€” slay, go build some indexes 🌈

πŸ“¦ where this page comes from