feat: Introduce the Criteria struct

This commit is contained in:
Clément Renault 2018-10-10 16:57:21 +02:00
parent 7a668dde98
commit c56c35b45b
12 changed files with 243 additions and 159 deletions

View file

@ -6,7 +6,8 @@ use std::path::PathBuf;
use fst::Streamer;
use elapsed::measure_time;
use rocksdb::{DB, DBOptions, IngestExternalFileOptions};
use raptor::{automaton, Metadata, RankedStream, CommonWords};
use raptor::{automaton, Metadata, CommonWords};
use raptor::rank;
#[derive(Debug, StructOpt)]
pub struct CommandConsole {
@ -69,14 +70,21 @@ fn search(metadata: &Metadata, database: &DB, common_words: &CommonWords, query:
automatons.push(lev);
}
let mut stream = RankedStream::new(&metadata, automatons, 20);
let config = rank::Config {
criteria: rank::criterion::default(),
metadata: &metadata,
automatons: automatons,
limit: 20,
};
let mut stream = rank::RankedStream::new(config);
while let Some(document) = stream.next() {
let id_key = format!("{}-id", document.document_id);
let id_key = format!("{}-id", document.id);
let id = database.get(id_key.as_bytes()).unwrap().unwrap();
let id = unsafe { from_utf8_unchecked(&id) };
print!("{} ", id);
let title_key = format!("{}-title", document.document_id);
let title_key = format!("{}-title", document.id);
let title = database.get(title_key.as_bytes()).unwrap().unwrap();
let title = unsafe { from_utf8_unchecked(&title) };
println!("{:?}", title);

View file

@ -7,7 +7,7 @@ use std::path::PathBuf;
use std::error::Error;
use std::sync::Arc;
use raptor::rank::RankedStream;
use raptor::rank;
use raptor::{automaton, Metadata, CommonWords};
use rocksdb::{DB, DBOptions, IngestExternalFileOptions};
use fst::Streamer;
@ -100,26 +100,33 @@ where M: AsRef<Metadata>,
automatons.push(lev);
}
let mut stream = RankedStream::new(metadata.as_ref(), automatons, 20);
let config = rank::Config {
criteria: rank::criterion::default(),
metadata: metadata.as_ref(),
automatons: automatons,
limit: 20,
};
let mut stream = rank::RankedStream::new(config);
let mut body = Vec::new();
write!(&mut body, "[")?;
let mut first = true;
while let Some(document) = stream.next() {
let title_key = format!("{}-title", document.document_id);
let title_key = format!("{}-title", document.id);
let title = database.as_ref().get(title_key.as_bytes()).unwrap().unwrap();
let title = unsafe { from_utf8_unchecked(&title) };
let description_key = format!("{}-description", document.document_id);
let description_key = format!("{}-description", document.id);
let description = database.as_ref().get(description_key.as_bytes()).unwrap().unwrap();
let description = unsafe { from_utf8_unchecked(&description) };
let image_key = format!("{}-image", document.document_id);
let image_key = format!("{}-image", document.id);
let image = database.as_ref().get(image_key.as_bytes()).unwrap().unwrap();
let image = unsafe { from_utf8_unchecked(&image) };
let document = Document {
id: document.document_id,
id: document.id,
title: title,
description: description,
image: image,