Pull request in order to avoid duplicate keywords and save them properly.#3
Open
merlin-Albe wants to merge 1 commit intomackstar:masterfrom
Open
Pull request in order to avoid duplicate keywords and save them properly.#3merlin-Albe wants to merge 1 commit intomackstar:masterfrom
merlin-Albe wants to merge 1 commit intomackstar:masterfrom
Conversation
…save them properly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello mackstar,
Working on our project I had to avoid saving duplicate keywords, however a simple array_unique() applied to the array_map() seems to save stuff uncorrectly.
Here's an example. I have the following array of keywords to save:
array(
0 => 'Alberto',
1 => 'Italian',
2 => 'guy',
3 => 'Francesco',
4 => 'Italian',
5 => 'developer'
);
the resulting array from the array_unique() will be:
array(
0 => 'Alberto',
1 => 'Italian',
2 => 'guy',
3 => 'Francesco',
5 => 'developer'
);
with correct unique values but not preserved keys. Saving this array as the document "_keywords" field will produce something like:
"_keywords" : {
"0" : "alberto",
"1" : "italian",
"2" : "guy",
"3" : "francesco",
"5" : "developer"
}
which makes the saved document unsearchable, since the _keywords should be:
"_keywords" : {
"alberto",
"italian",
"guy",
"francesco",
"developer"
}
For this reason I added the loop in order to preserve the array keys and save stuff properly.
I look forward to receiving your reply.
Thanks.