-
Notifications
You must be signed in to change notification settings - Fork 4
Add cropping and update _formatted
behavior
#183
Conversation
f59ffb4
to
6b90b14
Compare
I ping you @MarinPostma because I cannot request you on your own PR ^^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it we could use a FormatOptions
struct for each field, saying whether a field in cropped or highlighted, and pass a HashMap<FieldId, FormatOptions>
You can now review @MarinPostma! 😄 I did not use the regexp but I did something different with the help of @ManyTheFish and @Kerollmops 😇 |
meilisearch-http/src/index/search.rs
Outdated
let ids_in_formatted = formatted_options | ||
.keys() | ||
.cloned() | ||
.collect::<HashSet<_>>() | ||
.intersection(&displayed_ids) | ||
.cloned() | ||
.collect::<HashSet<_>>() | ||
.union(&to_retrieve_ids) | ||
.cloned() | ||
.sorted() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could instead:
- Not add fields that are not in
_formatted
in theformatted_options
map - Add the fields that are not formatted but in
_formatted
to theformatted_options
but with no formatting.
This would save us needless alllocations, and simplify the code (formatted options being the single source needed to created the _formatted
field.)
Since the map is indexed by FieldId
, we can simply use a BTreeMap
instead to have all the formatted fields sorted in the right order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
almost there :)
Co-authored-by: marin <postma.marin@protonmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked with @MarinPostma: this approval represents the Marin's approval
bors merge
Build succeeded: |
if format_options.highlight && token.is_word() && matcher.matches(token.text()).is_some() { | ||
let mut new_word = String::new(); | ||
new_word.push_str(&self.marks.0); | ||
if let Some(match_len) = matcher.matches(token.text()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@curquiza Calling matcher.matches(token.text())
two times here is not quite good, this method can be CPU intensive in the case of a short prefix in the user query for example, and remember that you call it on all of the document tokens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the info @Kerollmops, I'll fix that
TODO:
attributesToRetrieve
and_formatted
behavior #203