Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field accessor trait? #19

Open
marcus-pousette opened this issue Aug 21, 2022 · 3 comments
Open

Field accessor trait? #19

marcus-pousette opened this issue Aug 21, 2022 · 3 comments
Assignees

Comments

@marcus-pousette
Copy link
Collaborator

marcus-pousette commented Aug 21, 2022

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
Copy link
Collaborator

tmpfs commented Aug 21, 2022

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 marcus-pousette self-assigned this Aug 26, 2022
@marcus-pousette
Copy link
Collaborator Author

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

@marcus-pousette
Copy link
Collaborator Author

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants