private function search(OrmManager $orm, JsonApiQuery $documentQuery) { $term = $documentQuery->getFilter('term'); if ($term) { $term = '%' . $term . '%'; } $geoLocationModel = $orm->getGeoLocationModel(); $geoLocationLocalizedModel = $orm->getGeoLocationLocalizedModel(); // query localized table if ($term) { $query = $geoLocationLocalizedModel->createQuery(); $query->setFields('{entry}, {name}'); $query->setLimit(100); $query->addCondition('{locale} = %1%', $orm->getLocale()); $query->addCondition('{name} LIKE %1%', $term); $geoLocationLocalizedResult = $query->query('entry'); } // query main table $query = $geoLocationModel->createQuery(); $query->setFields('{id}, {path}, {code}'); $query->setLimit(100); if ($term) { if (!$geoLocationLocalizedResult) { $query->addCondition('{code} LIKE %1%', $term); } else { $query->addCondition('{id} IN %1%', array_keys($geoLocationLocalizedResult)); } } $type = $documentQuery->getFilter('type'); if ($type) { if (is_array($type)) { $query->addCondition('{type} IN %1%', $type); } elseif (strpos($type, ',')) { $query->addCondition('{type} IN %1%', explode(',', $type)); } else { $query->addCondition('{type} = %1%', $type); } } $path = $documentQuery->getFilter('path'); if ($path) { if (strpos($path, '~') == false) { $path = '~' . $path . '~'; } $query->addCondition('{path} LIKE %1%', '%' . $path . '%'); } $geoLocationResult = $query->query(); // foreach ($geoLocationResult as $index => $geoLocation) { // $result[$index] = $index; // } // merge result return $geoLocationResult; }