Skip to content

Commit

Permalink
Merge pull request #35 from fulmicoton/bug/4
Browse files Browse the repository at this point in the history
Closes #4
  • Loading branch information
fulmicoton committed Oct 16, 2016
2 parents e1ed36f + 9358eb3 commit 8f6633d
Show file tree
Hide file tree
Showing 42 changed files with 1,513 additions and 403 deletions.
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@ rand = "0.3"
[build-dependencies]
gcc = "0.3"

# [profile.release]
# debug = true
[profile.release]
opt-level = 3
debug = false
lto = true
debug-assertions = false
2 changes: 1 addition & 1 deletion examples/simple_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() {
// Let's create a temporary directory for the
// sake of this example
if let Ok(dir) = TempDir::new("tantivy_example_dir") {
run_example(&dir.path()).unwrap();
run_example(dir.path()).unwrap();
dir.close().unwrap();
}
}
Expand Down
23 changes: 15 additions & 8 deletions src/collector/top_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use Score;

// Rust heap is a max-heap and we need a min heap.
#[derive(Clone, Copy)]
struct GlobalScoredDoc(Score, DocAddress);
struct GlobalScoredDoc {
score: Score,
doc_address: DocAddress
}

impl PartialOrd for GlobalScoredDoc {
fn partial_cmp(&self, other: &GlobalScoredDoc) -> Option<Ordering> {
Expand All @@ -21,9 +24,9 @@ impl PartialOrd for GlobalScoredDoc {
impl Ord for GlobalScoredDoc {
#[inline]
fn cmp(&self, other: &GlobalScoredDoc) -> Ordering {
other.0.partial_cmp(&self.0)
other.score.partial_cmp(&self.score)
.unwrap_or(
other.1.cmp(&self.1)
other.doc_address.cmp(&self.doc_address)
)
}
}
Expand Down Expand Up @@ -87,7 +90,7 @@ impl TopCollector {
.collect();
scored_docs.sort();
scored_docs.into_iter()
.map(|GlobalScoredDoc(score, doc_address)| (score, doc_address))
.map(|GlobalScoredDoc {score, doc_address}| (score, doc_address))
.collect()
}

Expand All @@ -110,13 +113,17 @@ impl Collector for TopCollector {
if self.at_capacity() {
// It's ok to unwrap as long as a limit of 0 is forbidden.
let limit_doc: GlobalScoredDoc = *self.heap.peek().expect("Top collector with size 0 is forbidden");
if limit_doc.0 < scored_doc.score() {
let wrapped_doc = GlobalScoredDoc(scored_doc.score(), DocAddress(self.segment_id, scored_doc.doc()));
self.heap.replace(wrapped_doc);
if limit_doc.score < scored_doc.score() {
let mut mut_head = self.heap.peek_mut().expect("Top collector with size 0 is forbidden");
mut_head.score = scored_doc.score();
mut_head.doc_address = DocAddress(self.segment_id, scored_doc.doc());
}
}
else {
let wrapped_doc = GlobalScoredDoc(scored_doc.score(), DocAddress(self.segment_id, scored_doc.doc()));
let wrapped_doc = GlobalScoredDoc {
score: scored_doc.score(),
doc_address: DocAddress(self.segment_id, scored_doc.doc())
};
self.heap.push(wrapped_doc);
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ pub trait HasLen {
fn is_empty(&self,) -> bool {
self.len() == 0
}
}
}
3 changes: 1 addition & 2 deletions src/common/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ impl BinarySerializable for String {
#[cfg(test)]
mod test {

use std::io::Cursor;
use common::VInt;
use super::*;

Expand All @@ -131,7 +130,7 @@ mod test {
else {
v.serialize(&mut buffer).unwrap();
}
let mut cursor = Cursor::new(&buffer[..]);
let mut cursor = &buffer[..];
let deser = T::deserialize(&mut cursor).unwrap();
assert_eq!(deser, v);
}
Expand Down

0 comments on commit 8f6633d

Please sign in to comment.