Added methods to extract the matching terms. First stab

This commit is contained in:
Paul Masurel
2018-08-30 09:47:19 +09:00
parent a12d211330
commit 6704ab6987
4 changed files with 31 additions and 5 deletions

View File

@@ -27,6 +27,7 @@ mod weight;
mod vec_docset;
pub(crate) mod score_combiner;
pub use self::weight::MatchingTerms;
pub use self::intersection::Intersection;
pub use self::union::Union;

View File

@@ -5,6 +5,8 @@ use downcast;
use std::fmt;
use Result;
use SegmentLocalId;
use DocAddress;
use query::weight::MatchingTerms;
/// The `Query` trait defines a set of documents and a scoring method
/// for those documents.

View File

@@ -6,7 +6,6 @@ use std::collections::HashSet;
use Term;
use std::collections::BTreeMap;
pub struct MatchingTerms {
doc_to_terms: BTreeMap<DocId, HashSet<Term>>
}

View File

@@ -1,10 +1,17 @@
use htmlescape::encode_minimal;
use htmlescape::encode_minimal;
use schema::FieldValue;
use std::collections::BTreeMap;
use itertools::Itertools;
use tokenizer::BoxedTokenizer;
use tokenizer::{Token, TokenStream};
use Index;
use Result;
use Term;
use query::Query;
use DocAddress;
use DocId;
use Searcher;
use query::MatchingTerms;
#[derive(Debug)]
pub struct HighlightSection {
@@ -179,12 +186,29 @@ fn select_best_fragment_combination<'a>(
}
}
fn matching_terms(query: &Query, searcher: &Searcher, doc_addresses: &[DocAddress]) -> Result<()> {
let weight = query.weight(searcher, false)?;
let mut doc_groups = doc_addresses
.iter()
.group_by(|doc_address| doc_address.0);
for (segment_ord, doc_addrs) in doc_groups.into_iter() {
let doc_addrs_vec: Vec<DocId> = doc_addrs.map(|doc_addr| doc_addr.1).collect();
let mut matching_terms = MatchingTerms::from_doc_ids(&doc_addrs_vec[..]);
let segment_reader = searcher.segment_reader(segment_ord);
weight.matching_terms(segment_reader, &mut matching_terms)?;
}
Ok(())
}
pub fn generate_snippet<'a>(
doc: &'a [FieldValue],
doc: &'a [DocAddress],
index: &Index,
query: &Query,
terms: Vec<Term>,
max_num_chars: usize,
) -> Snippet {
max_num_chars: usize) -> Snippet {
unimplemented!();
}