quantleaf / probly-search

A lightweight full-text search library written in Rust that provides full control over the scoring calculations
MIT License
60 stars 5 forks source link

Field accessor trait? #19

Open marcus-pousette opened 2 years ago

marcus-pousette commented 2 years ago

In the current solution you define extraction functions and pass the as an array in add_document:

pub fn add_document<D> (
        &mut self,
        field_accessors: &[FieldAccessor<D>],
        tokenizer: Tokenizer,
        key: T,
        doc: &D,
    )
    ...

A maybe more idiomatic solution would be to create a Trait, called something like Indexable

trait Indexable
{
    fn key(&self) -> &str,
    fn extract_fields(&self) -> &[&str]
} 

Then the add_document method will look like

pub fn add_document<D: Indexable> (
        &mut self,
        doc: &D,
)
tmpfs commented 2 years ago

I prefer this approach as it is more idiomatic and using a trait rather than a type definition is more extensible. Good idea 👍

marcus-pousette commented 2 years ago

Will try to get a PR up soon as I have time

marcus-pousette commented 1 year ago

@tmpfs I have not given up on this task, but I have been very busy this autumn and have not have time to work on this lib at all. Hopefully will have more time after new year!