Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Add cropping and update _formatted behavior #183

Merged
merged 34 commits into from
Jun 18, 2021
Merged

Add cropping and update _formatted behavior #183

merged 34 commits into from
Jun 18, 2021

Conversation

MarinPostma
Copy link
Contributor

@MarinPostma MarinPostma commented May 5, 2021

TODO:

@curquiza curquiza force-pushed the crop branch 2 times, most recently from f59ffb4 to 6b90b14 Compare June 3, 2021 14:45
@curquiza curquiza changed the title crop skeleton Add cropping Jun 8, 2021
@curquiza curquiza marked this pull request as ready for review June 8, 2021 15:34
@curquiza curquiza linked an issue Jun 8, 2021 that may be closed by this pull request
@curquiza
Copy link
Member

curquiza commented Jun 8, 2021

I ping you @MarinPostma because I cannot request you on your own PR ^^

Copy link
Contributor Author

@MarinPostma MarinPostma left a 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>

meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
meilisearch-http/src/index/search.rs Show resolved Hide resolved
meilisearch-http/src/index/search.rs Show resolved Hide resolved
meilisearch-http/src/index/search.rs Show resolved Hide resolved
@curquiza curquiza changed the title Add cropping Add cropping and update _formatted behavior Jun 14, 2021
@curquiza curquiza linked an issue Jun 14, 2021 that may be closed by this pull request
7 tasks
meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
@curquiza
Copy link
Member

You can now review @MarinPostma! 😄 I did not use the regexp but I did something different with the help of @ManyTheFish and @Kerollmops 😇
I also solved #203 compared to your preview review.

meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
Comment on lines 161 to 170
let ids_in_formatted = formatted_options
.keys()
.cloned()
.collect::<HashSet<_>>()
.intersection(&displayed_ids)
.cloned()
.collect::<HashSet<_>>()
.union(&to_retrieve_ids)
.cloned()
.sorted()
Copy link
Contributor Author

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 the formatted_options map
  • Add the fields that are not formatted but in _formatted to the formatted_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.

meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
Copy link
Contributor Author

@MarinPostma MarinPostma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost there :)

meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
meilisearch-http/src/index/search.rs Outdated Show resolved Hide resolved
meilisearch-http/src/index/search.rs Show resolved Hide resolved
curquiza and others added 2 commits June 17, 2021 18:00
Co-authored-by: marin <postma.marin@protonmail.com>
@curquiza curquiza requested a review from Kerollmops June 18, 2021 11:15
@curquiza curquiza dismissed Kerollmops’s stale review June 18, 2021 11:16

The request was implemented 🤘

Copy link
Member

@curquiza curquiza left a 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

@bors
Copy link
Contributor

bors bot commented Jun 18, 2021

@bors bors bot merged commit c1b6f0e into main Jun 18, 2021
@bors bors bot deleted the crop branch June 18, 2021 11:39
Comment on lines +499 to +502
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()) {
Copy link
Member

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.

Copy link
Contributor Author

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

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

Successfully merging this pull request may close these issues.

attributesToRetrieve and _formatted behavior Search result cropping
3 participants