Currently adding the same field more than once will not work. Only the last added search field will actually contain any value.
This is due to the extractFields() methods in src/Utility.php, it uses the property path as unique keys mapped to search fields.
Adding the same field twice is useful if you want to index it as String and as Full Text.

Comments

jeroen.b created an issue. See original summary.

jeroen.b’s picture

Status: Needs work » Needs review
StatusFileSize
new4.1 KB

Here's a fix.

Status: Needs review » Needs work

The last submitted patch, 2: search_api-2696131-1.patch, failed testing.

The last submitted patch, 2: search_api-2696131-1.patch, failed testing.

jeroen.b’s picture

Status: Needs work » Needs review
StatusFileSize
new6.65 KB

Trying to fix tests and aggregation.

Status: Needs review » Needs work

The last submitted patch, 5: search_api-2696131-5.patch, failed testing.

jeroen.b’s picture

StatusFileSize
new7 KB
jeroen.b’s picture

Status: Needs work » Needs review
jeroen.b’s picture

Status: Needs review » Needs work
jeroen.b’s picture

Status: Needs work » Needs review
borisson_’s picture

Status: Needs review » Needs work
StatusFileSize
new1.36 KB

I think we need a new test case for this as well, but the code looks great so far.

jeroen.b’s picture

Status: Needs work » Needs review
StatusFileSize
new1.67 KB
new7.56 KB

You are right.
Adding the same field twice works fine though, it's extracting the values that is wrong.
I created a new patch that extends the extract tests.

drunken monkey’s picture

Component: General code » Framework
Status: Needs review » Needs work

Thanks a lot for reporting this issue! That is indeed a curious problem, seems I ignored this completely when changing the fields system. Unfortunate that I never checked it works, or included that in the tests.
All the better that you're now adding a test for this, in addition to implementing a fix for this problem – awesome job!

Just two notes on the patch:

  1. If you change the parameter of Utility::extractFields(), you have to also adapt its documentation.
  2. The Field objects already have information on their property path (and field ID). If we can't use the convenient method of requiring the property paths as keys, it seems unnecessary to have any kind of extra information in the parameter. Just take an array of field objects (with arbitrary keys) and work on that. (Also makes the test method simpler again – you can just have a numerically-indexed array of field objects.)

Otherwise, again: great job!

@ borisson_: As in the other issue – your patch file is broken. It seems to contain control characters for changing the colors, or something like that?

jeroen.b’s picture

Thanks for the feedback, I'll address the issues soon.

I think @borisson_ runs git diff in a colered shell and then copies the output.
He probably wants to use git diff > [project]-[issue-number]-[comment].patch and then upload the resulting file.

borisson_’s picture

I use do git diff > *.patch, but I recently started using https://github.com/so-fancy/diff-so-fancy with custom colors, that broke the patches. Luckily that patch was not very useful anyway.

jeroen.b’s picture

@drunken monkey, I was just trying to just pass an array of Field[] objects, but then we have no way to store the nested path for the recursive extraction.

drunken monkey’s picture

Status: Needs work » Needs review
StatusFileSize
new7.71 KB

Oh, that's right, of course! Sorry about that!
Then maybe like in the attached patch, keeping the code more or less the same, but with arrays of field objects instead of single objects?
(We could also change the code to recognize both cases, but such parameter overloading is rarely a good idea.)

jeroen.b’s picture

StatusFileSize
new7.07 KB
new7.67 KB

I don't really like that.
Modified the patch.

Status: Needs review » Needs work

The last submitted patch, 40: search_api-2696131-40.patch, failed testing.

The last submitted patch, 40: search_api-2696131-40.patch, failed testing.

drunken monkey’s picture

Hm, yes, that would work, too. If you can make it into a working implementation, it's definitely an alternative to consider.
Please just:
- Also adapt the "Highlight" processor.
- Add an assertion to the test proving this is fixed (like I did).
- Fix the method's documentation.
- Avoid recursing multiple times into the same property (i.e., keep grouping by (direct) property).

@ Joris: Do you have any preference here?

borisson_’s picture

I think I prefer the way @drunken monkey fixed it in #39 over the solution in #40. I can live with either one though.

drunken monkey’s picture

Status: Needs work » Needs review

OK, then let's stick with that variant. Thanks for your input!

Anything else, or can I commit #39?

The last submitted patch, 33: can_t_add_the_same--test-only.patch, failed testing.

The last submitted patch, 33: can_t_add_the_same--test-only.patch, failed testing.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

You can go ahead and commit #39.

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Great, thanks for reviewing!
Committed.
Thanks again, everyone!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.