Problem/Motivation

We're working on indexing field types not in the current version of the module. Our example is a geopoint, which means the value we're indexing is an array. See documentation: https://typesense.org/docs/0.25.1/api/geosearch.html#searching-within-a-...

I came across this bug/mistake in the code causing this error:

TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in count() (line 367 of modules/contrib/search_api_typesense/src/Api/SearchApiTypesenseService.php).

Code causing error:

public function prepareItemValue($value, $type) {
    if (is_array($value) && count($value <= 1)) {
      $value = reset($value);
    }

Steps to reproduce

Clone any of the data_type plugins and return an array. Could be as simple as:

return (string) [$value, $value];

Proposed resolution

Easy to fix by moving the closing parentheses so it's "count($value) <= 1" instead of "count($value <= 1)".

Remaining tasks

Test patch

User interface changes

N/A

API changes

N/A

Data model changes

N/A

CommentFileSizeAuthor
#2 fix-count-check-3403080-2.patch581 byteskhaled.zaidan

Comments

khaled.zaidan created an issue. See original summary.

khaled.zaidan’s picture

StatusFileSize
new581 bytes

Attaching patch for suggested fix.

khaled.zaidan’s picture

Status: Active » Needs review
keshavv’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed that there is an issue and the #2 patch works well. This is a minor mistake. So we can merge it.

lussoluca’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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