Skip to content

Pull request in order to avoid duplicate keywords and save them properly.#3

Open
merlin-Albe wants to merge 1 commit intomackstar:masterfrom
merlin-Albe:master
Open

Pull request in order to avoid duplicate keywords and save them properly.#3
merlin-Albe wants to merge 1 commit intomackstar:masterfrom
merlin-Albe:master

Conversation

@merlin-Albe
Copy link

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.

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

Successfully merging this pull request may close these issues.

1 participant