parent
2a5ae8962d
commit
74ca327de6
|
@ -276,6 +276,20 @@ impl Searcher {
|
|||
self.inner.segment_readers().len()
|
||||
}
|
||||
|
||||
/// Return the overall number of documents containing
|
||||
/// the given term.
|
||||
#[pyo3(signature = (field_name, field_value))]
|
||||
fn doc_freq(
|
||||
&self,
|
||||
field_name: &str,
|
||||
field_value: &Bound<PyAny>,
|
||||
) -> PyResult<u64> {
|
||||
// Wrap the tantivy Searcher `doc_freq` method to return a PyResult.
|
||||
let schema = self.inner.schema();
|
||||
let term = crate::make_term(schema, field_name, field_value)?;
|
||||
self.inner.doc_freq(&term).map_err(to_pyerr)
|
||||
}
|
||||
|
||||
/// Fetches a document from Tantivy's store given a DocAddress.
|
||||
///
|
||||
/// Args:
|
||||
|
|
|
@ -337,6 +337,9 @@ class Searcher:
|
|||
def doc(self, doc_address: DocAddress) -> Document:
|
||||
pass
|
||||
|
||||
def doc_freq(self, field_name: str, field_value: Any) -> int:
|
||||
pass
|
||||
|
||||
class IndexWriter:
|
||||
def add_document(self, doc: Document) -> int:
|
||||
pass
|
||||
|
|
|
@ -64,6 +64,12 @@ class TestClass(object):
|
|||
|
||||
assert len(result.hits) == 1
|
||||
|
||||
def test_doc_freq(self, ram_index):
|
||||
index = ram_index
|
||||
searcher = index.searcher()
|
||||
doc_freq = searcher.doc_freq("body", "and")
|
||||
assert doc_freq == 3
|
||||
|
||||
def test_and_aggregate(self, ram_index_numeric_fields):
|
||||
index = ram_index_numeric_fields
|
||||
query = Query.all_query()
|
||||
|
|
Loading…
Reference in New Issue