mackstar/li3_searchable — pull request #3 by merlin-Albe (2012-05-08 16:16:23+00:00)
Title: Pull request in order to avoid duplicate keywords and save them properly.

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.