Plucen...Reader(3pm)

πŸ“¦
version 1.25 Β· 2 versions
  • 1.25 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.25 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ Plucene::Index::Reader β€” the abstract baddie for accessing an index ✨

okay bestie, listen up πŸ’– this is Plucene::Index::Reader from the User Contributed Perl Documentation, and it's giving abstract class energy β€” like, it's the vibe, not the full outfit. let's get into it πŸŽ€


🌸 NAME 🌸

Plucene::Index::Reader β€” the abstract class for accessing an index. no cap, that's literally it πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so. IndexReader is an abstract class, and what it does is provide an interface for accessing an index. and here's the slay part β€” searching an index happens entirely through this abstract interface, which means literally any subclass that implements it is automatically searchable. iconic behavior honestly πŸ‘‘

concrete subclasses of IndexReader are usually constructed with a call to the static method open. that's the move. that's how you get one ✨

and now for the efficiency tea β˜• β€” in this API, documents are often referred to via document numbers: non-negative integers, each one naming a unique document in the index. but bestie, these document numbers are ephemeral β€” they may change as documents get added to and deleted from an index. so clients should not rely on a given document having the same number between sessions. fr fr, do not do that. it's giving undefined behavior and we're not about that life πŸ’€


πŸ’œ METHODS πŸ’œ

πŸ“ new

my $reader = Plucene::Index::Reader->new($dir_name);

this creates a new Plucene::Index::Reader with the directory you passed in. that's it, that's the whole thing 🫢

🌈 open

# If there is only one segment
my Plucene::Index::SegmentReader $seg_read = $reader->open;

# If there are many segments
my Plucene::Index::SegmentsReader $seg_read = $reader->open;

returns an IndexReader reading the index in the given Directory. one segment, many segments, doesn't matter β€” it's got you πŸ’«

⭐ last_modified

my $last_modified = Plucene::Index::Reader->last_modified($directory);

yep. that's the one. returns the last modified, as you'd expect 😌

🧚 index_exists

if (Plucene::Index::Reader->index_exists($directory)){ ... }

does the index exist? check it and find out bestie πŸ’–

πŸŽ€ is_locked

if (Plucene::Index::Reader->is_locked($directory)){ ... }

is it locked? the vibes will tell you πŸ”’

πŸ‘‘ delete

$reader->delete($doc);

deletes the doc. bye bye 🫑

πŸ’… delete_term

$reader->delete_term($term);

this will delete all the documents which contain the passed term. all of them. every single one. periodt πŸŒͺ️

πŸ”₯ close

$reader->close;

closes it. we love a clean exit ✨

πŸ’€ unlock

$reader->unlock($directory);

unlocks the directory. freedom πŸ¦‹


πŸ™ˆ and then there's these ones…

these must be defined in a subclass β€” no exceptions, bestie, they're abstract for a reason:

  • num_docs
  • max_doc
  • document
  • is_deleted
  • norms
  • terms
  • doc_freq
  • term_docs
  • term_positions
  • _do_delete
  • _do_close
like, genuinely, if you're subclassing this, you have to define all of them. it's not optional and it's not a suggestion. it's giving homework πŸ“š

okay that's the whole page, you ate it, you understood it, you're basically a search engine engineer now πŸ’–βœ¨

this has been Plucen...Reader(3pm) β€” written up against perl v5.36.0, dated 2022-12-04. mwah, love you, bye πŸ‘‘πŸ’…πŸŒˆ

πŸ“¦ where this page comes from