Skip to content

Commit

Permalink
feat: Fix the ranking algorithm to sort only the needed documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Jul 1, 2018
1 parent 82c248a commit fcd827d
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 229 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions raptor-indexer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions raptor-indexer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ where P: AsRef<Path>
fs::set_permissions(&path, perms)
}

fn is_readonly<P>(path: P) -> io::Result<bool>
where P: AsRef<Path>
{
fs::metadata(&path).map(|m| m.permissions().readonly())
}

fn main() {
let data = File::open("products.json_lines").unwrap();
let data = BufReader::new(data);
Expand All @@ -54,6 +60,18 @@ fn main() {
}
};

let map_file = "map.fst";
let values_file = "values.vecs";

for file in &[map_file, values_file] {
match is_readonly(file) {
Ok(true) => panic!("the {:?} file is readonly, please make it writeable", file),
Err(ref e) if e.kind() == io::ErrorKind::NotFound => (),
Err(e) => panic!("{:?}", e),
_ => (),
}
}

let mut builder = DocIndexMapBuilder::new();
for line in data.lines() {
let line = line.unwrap();
Expand Down Expand Up @@ -83,13 +101,13 @@ fn main() {
}
}

let map = File::create("map.fst").unwrap();
let values = File::create("values.vecs").unwrap();
let map = File::create(map_file).unwrap();
let values = File::create(values_file).unwrap();

let (map, values) = builder.build(map, values).unwrap();

set_readonly("map.fst", true).unwrap();
set_readonly("values.vecs", true).unwrap();
set_readonly(map_file, true).unwrap();
set_readonly(values_file, true).unwrap();

println!("Checking the dump consistency...");
unsafe { DocIndexMap::from_paths("map.fst", "values.vecs").unwrap() };
Expand Down
26 changes: 13 additions & 13 deletions raptor-search/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions raptor-search/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ extern crate fst;
extern crate raptor;
extern crate elapsed;

use std::{env, fs};
use std::process::Command;
use std::env;
use std::io::{self, Write};
use elapsed::measure_time;
use fst::Streamer;
Expand All @@ -21,7 +20,8 @@ fn search(map: &DocIndexMap, lev_builder: &LevBuilder, query: &str) {
while let Some(document_id) = stream.next() {
print!("{:?}", document_id);

/* only here to debug !
// /* only here to debug !
use std::{fs, process::Command};
if let Ok(_) = fs::File::open("products.json_lines") {
let output = Command::new("rg")
.arg(document_id.to_string())
Expand Down
2 changes: 1 addition & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<T> Values<T> {
let cap = raw.iter().map(Vec::len).sum();
let mut values = Vec::with_capacity(cap);

for v in &raw {
for mut v in &raw {
let len = v.len() as u64;
let start = ranges.last().map(|&Range { end, .. }| end).unwrap_or(0);

Expand Down

0 comments on commit fcd827d

Please sign in to comment.