Make the export words FST export infos subcommand outputs to stdout

This commit is contained in:
Clément Renault 2020-12-02 10:43:22 +01:00
parent 85d51ab228
commit 16755b26e2
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -135,15 +135,11 @@ enum Command {
word2: String,
},
/// Outputs the words FST to disk.
/// Outputs the words FST to standard output.
///
/// One can use the FST binary helper to dissect and analyze it,
/// you can install it using `cargo install fst-bin`.
ExportWordsFst {
/// The path where the FST will be written.
#[structopt(short, long, default_value = "words.fst")]
output: PathBuf,
},
ExportWordsFst,
/// Outputs the documents as JSON lines to the standard output.
///
@ -187,7 +183,7 @@ pub fn run(opt: Opt) -> anyhow::Result<()> {
WordPairProximitiesDocids { full_display, word1, word2 } => {
word_pair_proximities_docids(&index, &rtxn, !full_display, word1, word2)
},
ExportWordsFst { output } => export_words_fst(&index, &rtxn, output),
ExportWordsFst => export_words_fst(&index, &rtxn),
ExportDocuments => export_documents(&index, &rtxn),
PatchToNewExternalIds => {
drop(rtxn);
@ -485,15 +481,15 @@ fn facet_stats(index: &Index, rtxn: &heed::RoTxn, field_name: String) -> anyhow:
Ok(())
}
fn export_words_fst(index: &Index, rtxn: &heed::RoTxn, output: PathBuf) -> anyhow::Result<()> {
use std::fs::File;
fn export_words_fst(index: &Index, rtxn: &heed::RoTxn) -> anyhow::Result<()> {
use std::io::Write as _;
let mut output = File::create(&output)
.with_context(|| format!("failed to create {} file", output.display()))?;
let mut stdout = io::stdout();
let words_fst = index.words_fst(rtxn)?;
output.write_all(words_fst.as_fst().as_bytes())?;
stdout.write_all(words_fst.as_fst().as_bytes())?;
Ok(())
}
fn export_documents(index: &Index, rtxn: &heed::RoTxn) -> anyhow::Result<()> {
use std::io::{BufWriter, Write as _};