#[non_exhaustive]pub struct Record {
pub raw: Value,
pub score: Option<f64>,
}Expand description
One concrete record passed into clustering.
raw is the original parsed item (never mutated). score is the
result of resolving the optional score path against raw and
converting to f64. None when no score was configured for this
run, or when the score path didn’t resolve to a number for this
particular record.
Record is #[non_exhaustive] — construct values via
Record::new or Record::from_items.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.raw: ValueOriginal parsed item, never mutated.
score: Option<f64>Resolved score, when a score path was configured and the value at that path was a JSON number.
Implementations§
Source§impl Record
impl Record
Sourcepub fn new(raw: Value) -> Self
pub fn new(raw: Value) -> Self
Construct a record with no score resolved.
§Examples
use face_core::Record;
use serde_json::json;
let r = Record::new(json!({"score": 0.9}));
assert!(r.score.is_none());Sourcepub fn from_items(items: Vec<Value>, score_path: Option<&str>) -> Vec<Record>
pub fn from_items(items: Vec<Value>, score_path: Option<&str>) -> Vec<Record>
Build a Vec<Record> from a parsed items list.
When score_path is None, all records have score: None.
When score_path is Some(path), the path is resolved against
each record. If the resolved value is a JSON number, it
becomes the record’s score. Otherwise the score remains None
(this is per-record permissiveness — strategies decide whether
missing scores are a problem).
--invert polarity flipping is the caller’s responsibility:
pass already-inverted scores via a follow-up apply_invert,
or build records via from_items and let the caller iterate.
Slice 5 does not auto-invert.
§Examples
use face_core::Record;
use serde_json::json;
let items = vec![
json!({"score": 0.9}),
json!({"score": "n/a"}),
];
let records = Record::from_items(items, Some("score"));
assert_eq!(records[0].score, Some(0.9));
assert_eq!(records[1].score, None);