public function getSearchQuery(ProductCondition $productCondition)
{
$query = null;
$query = $this->getSpecialAttributesSearchQuery($productCondition);
$this->prepareFieldValue($productCondition);
if ($query === null && !empty($productCondition->getValue())) {
$queryType = QueryInterface::TYPE_TERMS;
$queryParams = $this->getTermsQueryParams($productCondition);
if ($productCondition->getInputType() === 'string') {
$queryType = QueryInterface::TYPE_MATCH;
$queryParams = $this->getMatchQueryParams($productCondition);
} elseif (in_array($productCondition->getOperator(), ['>=', '>', '<=', '<'])) {
$queryType = QueryInterface::TYPE_RANGE;
$queryParams = $this->getRangeQueryParams($productCondition);
}
$query = $this->prepareQuery($queryType, $queryParams);
if (substr($productCondition->getOperator(), 0, 1) === '!') {
$query = $this->applyNegation($query);
}
$field = $this->getSearchField($productCondition);
if ($field->isNested()) {
$nestedPath = $field->getNestedPath();
$nestedQueryParams = ['query' => $query, 'path' => $nestedPath];
if (isset($this->nestedFilters[$nestedPath])) {
$nestedFilterClauses = [];
$nestedFilterClauses['must'][] = $this->nestedFilters[$nestedPath]->getFilter();
$nestedFilterClauses['must'][] = $nestedQueryParams['query'];
$nestedFilter = $this->queryFactory->create(QueryInterface::TYPE_BOOL, $nestedFilterClauses);
$nestedQueryParams['query'] = $nestedFilter;
}
$query = $this->queryFactory->create(QueryInterface::TYPE_NESTED, $nestedQueryParams);
}
}
return $query;
}