Skip to content

Commit 67337d2

Browse files
committed
Add documentation about new functionality
1 parent 261f690 commit 67337d2

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/document.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,25 @@ fn value_to_string(value: &Value) -> String {
128128
///
129129
/// Example:
130130
/// >>> doc = tantivy.Document(title="The Old Man and the Sea", body="...")
131-
131+
///
132+
/// For numeric fields, the [`Document`] constructor does not have any
133+
/// information about the type and will try to guess the type.
134+
/// Therefore, it is recommended to use the [`Document::from_dict()`],
135+
/// [`Document::extract()`], or `Document::add_*()` functions to provide
136+
/// explicit type information.
137+
///
138+
/// Example:
139+
/// >>> schema = (
140+
/// SchemaBuilder()
141+
/// .add_unsigned_field("unsigned")
142+
/// .add_integer_field("signed")
143+
/// .add_float_field("float")
144+
/// .build()
145+
/// )
146+
/// >>> doc = tantivy.Document.from_dict(
147+
/// {"unsigned": 1000, "signed": -5, "float": 0.4},
148+
/// schema,
149+
/// )
132150
#[pyclass]
133151
#[derive(Default)]
134152
pub(crate) struct Document {
@@ -330,6 +348,11 @@ impl Document {
330348

331349
#[pymethods]
332350
impl Document {
351+
/// Creates a new document with optional fields from `**kwargs`.
352+
///
353+
/// Note that the types of numeric fields are unknown here. To
354+
/// provide explicit type information, use the [from_dict()],
355+
/// [extend()], or `add_<type>()` functions.
333356
#[new]
334357
#[pyo3(signature = (**kwargs))]
335358
fn new(kwargs: Option<&PyDict>) -> PyResult<Self> {

0 commit comments

Comments
 (0)