Files
fil/docs/snippets/swift/plugins/word_count_processor.md
Henrik Jess Nielsen b4c07d3693
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s
Nomad changes
2026-06-01 23:40:55 +02:00

1.1 KiB

import Kreuzberg

final class WordCountProcessor: PostProcessor {
    func name() -> String {
        "word_count"
    }

    func version() -> String {
        "1.0.0"
    }

    func processingStage() -> String {
        "early"
    }

    func priority() -> Int32 {
        50
    }

    func process(result: ExtractionResult, config: ExtractionConfig) -> String {
        let content = result.content()
        let words = content.split(separator: " ").count

        // Metadata is not directly mutable via the FFI, so store in logs or use
        // a side-channel approach. For now, just track that processing happened.
        return "{\"ok\": null}"
    }

    func shouldProcess(result: ExtractionResult, config: ExtractionConfig) -> Bool {
        !result.content().isEmpty
    }

    func estimatedDurationMs(result: ExtractionResult) -> UInt64 {
        5
    }

    func initialize() -> String {
        "{\"ok\": null}"
    }

    func shutdown() -> String {
        "{\"ok\": null}"
    }
}

let processor = WordCountProcessor()
try Kreuzberg.registerPostProcessor(processor)