Currently, the QueryInterface::getFields() method documentation states that the return value will always be an array of strings (field IDs). However, if the method is called before preExecute() is run on the query (for whatever reason), the return value is actually NULL, thus violating the method contract.
There would be two fixes possible for this, as far as I can see:
- Just allow the method to also return
NULL and leave backends to call $index->getFulltextFields() themselves if they still need the fields.
- Move the fallback code for unspecified fields from
preExecute() to getFields() to make sure we always return an array.
I'm leaning towards the former option, but I'd be open to both. (The latter would have the advantage, e.g., that backends wouldn't have to adapt to the change.)
In any case, while implementing this we could also fix the following for fields():
// @todo Allow calling with NULL, and maybe rename to setFulltextFields().
public function fields(array $fields);
Comments
Comment #2
sdstyles commentedAdded fallback code for getField() method, also changed field() method.
Comment #4
sdstyles commentedComment #6
drunken monkeyThanks a lot for creating the patch, it's definitely a good start!
However, there's some problems with it currently:
Any particular reason you chose the second way of fixing this?
As said, I think I'd have preferred the former one (allowing a NULL return value).
Oh, also this is in the completely wrong method. It should, if at all, be in the query class's
getFulltextFields()method, not in the index class. (And should then be removed from the query class'spreExecute()method.)array $fields = NULLis the argument list I had in mind. (Also in the two other method definitions.)Comment #7
sdstyles commentedHi, I've used first proposed fix.
Comment #8
drunken monkeyGreat work, thanks! Looks pretty good now already. Some more nit-picking, though:
This can still use the array type hint if the default value is
NULL– a perhaps little-known but very handy feature of PHP (same for class/interface type hints).Exactly the other way round – "null" next to the
@returntag but then "NULL" in the description.Also, the description should say in which situation
NULLis returned. And I'd list the return types asstring[]|null, since that's the "main" type. (I usually put "null" last in such lists – but of course purely a matter of taste.)Also, now that
NULLis an allowed return value forgetFulltextFields(), we don't have to explicitly set them to anything inQuery::preProcess()– so, please remove that code, too.Otherwise, this is fine, I can probably commit it once these are fixed.
Thanks again!
Comment #9
sdstyles commentedChanged.
Comment #11
sdstyles commentedReverted.
Comment #12
drunken monkeyYes, when we change the contract for
getFields(), we of course also need to change the backend plugin accordingly.(Interdiff based on #9.)
Comment #14
drunken monkeyComment #15
drunken monkeyCommitted.
Thanks again for your great work on this!