Xapian:...atabase(3)

πŸ’– NAME πŸ’–

Search::Xapian::WritableDatabase β€” writable database object. This is the Xapian:...atabase(3) page from the User Contributed Perl Documentation, and yes bestie, we're getting into the write-y side of Xapian. πŸ¦‹

✨ DESCRIPTION ✨

This class is literally the Xapian database object you use for indexing. It's a subclass of Search::Xapian::Database, which is the one you use for searching. So think: WritableDatabase is the main character who gets to make changes, and Database is the one who reads. πŸ‘‘

🌸 METHODS 🌸

πŸŽ€ new <database> or new <path> <mode> πŸŽ€

Class constructor. It takes either a database object, or a path plus one of these modes:

  • DB_OPEN
  • DB_CREATE
  • DB_CREATE_OR_OPEN
  • DB_CREATE_OR_OVERWRITE

These are exported by Search::Xapian with the 'db' option. Slay. ✨

πŸ¦‹ clone πŸ¦‹

Return a clone of this class. Copy-paste but make it official. πŸ’…

🌈 flush 🌈

Flush to disk any modifications made to the database.

Okay so for efficiency reasons, when you're doing multiple updates to a database it is best β€” indeed, almost essential β€” to make as many modifications as memory will permit in a single pass through the database. To ensure this, Xapian batches up modifications. It's giving "trust the process." 🫢

flush may be called at any time to ensure that the modifications which have been made are written to disk: if the flush succeeds, all the preceding modifications will have been written to disk.

If any of the modifications fail, an exception will be thrown and the database will be left in a state in which each separate addition, replacement or deletion operation has either been fully performed or not performed at all: it is then up to the application to work out which operations need to be repeated. So yeah, your app has to do the emotional labor of figuring out what got done. 😭

Beware of calling flush too frequently: this will have a severe performance cost. Not me spam-calling flush and wondering why everything is slow πŸ’€

Note that flush need not be called explicitly: it will be called automatically when the database is closed, or when a sufficient number of modifications have been made. Xapian said "I got you, bestie." πŸ’–

⭐ add_document <document> ⭐

Add a new document to the database.

This method adds the specified document to the database, returning a newly allocated document ID. New ID just dropped. πŸŽ€

Note that this does not mean the document will immediately appear in the database; see flush() for more details.

As with all database modification operations, the effect is atomic: the document will either be fully added, or the document fails to be added and an exception is thrown β€” possibly at a later time when flush is called or the database is closed. So it's all-or-nothing, no messy half-adds. πŸ’…

🧚 delete_document <doc_id> 🧚

Delete a document from the database. This method removes the document with the specified document ID from the database.

Note that this does not mean the document will immediately disappear from the database; see flush() for more details.

As with all database modification operations, the effect is atomic: the document will either be fully removed, or the document fails to be removed and an exception is thrown β€” possibly at a later time when flush is called or the database is closed. Ghosting, but transactional. πŸ‘»

🌸 delete_document_by_term <term> 🌸

Delete any documents indexed by a term from the database. This method removes any documents indexed by the specified term from the database.

The intended use is to allow UIDs from another system to easily be mapped to terms in Xapian, although this method probably has other uses. Very "one term, many docs, bye." πŸ’…

πŸ’œ replace_document <doc_id> <document> πŸ’œ

Replace a given document in the database.

This method replaces the document with the specified document ID. Note that this does not mean the document will immediately change in the database; see flush() for more details.

As with all database modification operations, the effect is atomic: the document will either be fully replaced, or the document fails to be replaced and an exception is thrown β€” possibly at a later time when flush is called or the database is closed. Glow-up pending until flush. ✨

πŸ”₯ replace_document_by_term <unique_term> <document> πŸ”₯

Replace any documents matching a unique term.

This method replaces any documents indexed by the specified term with the specified document. If any documents are indexed by the term, the lowest document ID will be used for the document, otherwise a new document ID will be generated as for add_document. So it's "reuse the lowest ID if we can, otherwise make a new one." Periodt. πŸ’…

The intended use is to allow UIDs from another system to easily be mapped to terms in Xapian, although this method probably has other uses.

Note that this does not mean the document(s) will immediately change in the database; see flush() for more details.

As with all database modification operations, the effect is atomic: the document(s) will either be fully replaced, or the document(s) fail to be replaced and an exception is thrown β€” possibly at a later time when flush is called or the database is closed. All-or-nothing, even when it's plural. 🫢

πŸ“ add_spelling <word> <freqinc> πŸ“

Add a word to the spelling dictionary.

If the word is already present, its frequency is increased. Increment that lore. πŸ“ˆ

Parameters:

  • word β€” The word to add.
  • freqinc β€” How much to increase its frequency by (default 1).

πŸ§šβ€β™€οΈ remove_spelling <word> <freqdec> πŸ§šβ€β™€οΈ

Remove a word from the spelling dictionary.

The word's frequency is decreased, and if it would become zero or less then the word is removed completely. It's giving "so long, farewell, your frequency said bye." πŸ‘‹

Parameters:

  • word β€” The word to remove.
  • freqdec β€” How much to decrease its frequency by (default 1).

🌈 reopen 🌈

Re-open the database to ensure you are using the latest revision. Refresh the page, but for your database. πŸ”„

πŸ’– close πŸ’–

Close the database. This also implies a commit() unless a transaction is in progress. Important detail, bestie: commit(), not just a vibe. πŸ’…


πŸ”Ž SEE ALSO πŸ”Ž

  • Search::Xapian
  • Search::Xapian::Enquire
  • Search::Xapian::Database

okay bye bestie! This iconic page comes from perl v5.42.0, dated 2022-02-28, with the footer Xapian:...atabase(3). πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from