@param array $searchFields

@return array|\Illuminate\Database\Query\Expression
178688
protected function buildSelectQuery(array $searchFields)
    {
        $query = [];

        foreach ($searchFields as $searchField) {
            if (strpos($searchField, '::')) {

                $concatString = implode(', ', array_map( [$this, 'sanitizeColumnName'] , explode('::', $searchField)));

                $query[] = $this->buildSelectCriteria("CONCAT({$concatString})");
            } else {
                $query[] = $this->buildSelectCriteria($this->sanitizeColumnName($searchField));
            }
        }

        return \DB::raw( implode(' + ', $query) . ' AS ' . $this->relevanceFieldName);
    }
650917
protected function getFieldValues($fields)
    {
        $result = array();
        foreach ($fields as $id => $field) {
            if (isset($field['value'])) {
                $result[$id] = $field['value'];
            }
            if (!empty($field['fields'])) {
                /** @noinspection SlowArrayOperationsInLoopInspection */
                $result = array_merge($result, $this->getFieldValues($field['fields']));
            }
        }
        return $result;
    }
222333
protected function _createPlaceholders($fields)
        {
            if (!empty($fields)) {
                $db_fields = [];

                foreach($fields as $key => $value) {
                    // Process expression fields directly into the query
                    if(Arrays::exists($key, $this->_expr_fields)) {
                        $db_fields[] = $value;
                    } else {
                        $db_fields[] = '?';
                    }
                }

                return implode(', ', $db_fields);
            }
        }
175103
protected function buildSelectCriteria($searchField = null)
    {
        $criteria = [];

        foreach ($this->matchers as $matcher => $multiplier) {
            $criteria[] = $this->makeMatcher($searchField, $matcher, $multiplier);
        }

        return implode(' + ', $criteria);
    }
565859
protected function getSqlFields(array $fields)
    {
        $sql = array();
        foreach ($fields as $name => $info) {

            if (strpos($info['type'], 'text') !== false || $info['type'] === 'blob') {
                unset($info['default']);
            }

            $string = "{$info['type']}";

            if (isset($info['length'])) {
                $string .= "({$info['length']})";
            }

            if (!empty($info['not_null'])) {
                $string .= " NOT NULL";
            }

            if (isset($info['default'])) {
                $string .= " DEFAULT '{$info['default']}'";
            }

            if (!empty($info['primary'])) {
                $string .= " PRIMARY KEY";
            }

            if (!empty($info['auto_increment'])) {
                $string .= " /*!40101 AUTO_INCREMENT */"; // SQLite will ignore this comment
            }

            $sql[] = $name . ' ' . trim($string);
        }

        return implode(',', $sql);
    }
517297
public static function search($query, array $searchParameters = null)
    {
        $manager = static::getAlgoliaManager();

        return $manager->search(__CLASS__, $query, $searchParameters);
    }
181706
public function addQueryField($queryField,array $fields) {
        $valueField = $this->criteria->remove($queryField);
        if($valueField !== null){
            $this->addFieldLike($fields,$valueField);
        }
        return $this;
    }
664179
public function fieldQuery($field)
    {
        $query = $this->dsql()->del('fields');
        if (is_string($field)) {
            $field = $this->getElement($field);
        }
        $field->updateSelectQuery($query);

        return $query;
    }
474706
private function getSearchField($field)
    {
        if ($this->isStringDQLQuery($field)) {

            $dqlQuery = $field;

            $lexer = new Query\Lexer($field);

            // We have to rename some identifier or the execution will crash
            do {
                $lexer->moveNext();

                if ($this->isTheIdentifierILookingFor($lexer)) {

                    $replacement = sprintf("$1%s_%d$3", $lexer->lookahead['value'], mt_rand());
                    $pattern = sprintf("/([\(\s])(%s)([\s\.])/", $lexer->lookahead['value']);

                    $dqlQuery = preg_replace($pattern, $replacement, $dqlQuery);
                }

            } while($lexer->lookahead !== null);

            $dqlQuery = substr($dqlQuery, 0, strripos($dqlQuery, ")") + 1);

            return $dqlQuery;
        }

        $field = explode(' ', trim($field));

        return $field[0];
    }
766805
protected function getSearchFields()
    {
        if (null == $this->searchFields) {
            $field = $this->getEntityDescriptor()->getDisplayFiled();
            $this->searchFields = [
                $this->getEntityDescriptor()
                    ->getTableName().'.'.$field->getField()
            ];
        }
        return $this->searchFields;
    }
1054711
public function getSelectQueryBuilder(array $fields = array())
    {
        $connection = $this->getConnection();
        $qb         = $connection->createQueryBuilder();
        $fields     = array_merge($this->getFields(), $fields);
        $fields     = array_merge(array($this->getUniqueId()), $fields);

        foreach ($fields as &$field) {
            if (is_array($field)) {
                $keyName    = current(array_keys($field));
                $expression = current(array_values($field));
                $field      = "$expression AS " . $this->connection->quoteIdentifier($keyName);
            }
        }

        $queryBuilder = $qb->select($fields)->from($this->getTableName(), 't');
        return $queryBuilder;
    }
715661
public function get($conditions = [], $requiredField = [], $page = 0)
    {

        $searchParams['index'] = $this->index;
        $searchParams['type'] = $this->type;
        $searchParams['size'] = $this->maxResultsSize;
        $searchParams['from'] = $page * $this->maxResultsSize;
        $searchParams['body']['query']['bool']['must'] = [];
        $searchParams['_source_exclude']= ['PAG*'];

        $searchParams['body']['highlight']['order'] = 'score';
        $searchParams['body']['highlight']['fields'] = ['PAGE_*' => ['number_of_fragments' => 3], 'PAG_*' => ['number_of_fragments' => 3]];
        $searchParams['body']['highlight']['pre_tags'] = ['<strong>'];
        $searchParams['body']['highlight']['post_tags'] = ['</strong>'];

        foreach ($requiredField as $field) {
            $searchParams['body']['query']['bool']['must'][]['exists'] = ['field' => $field];
        }

        $filter = $this->makeFilterCondition($conditions);

        if(!empty($filter))$searchParams['body']['query']['bool']['must'][] = $filter;

        if($this->isModel)return $this->model->hydrateElasticsearchResult($this->client->search($searchParams));
        else return $this->client->search($searchParams);

    }
710586
public function selectFields($fields)
    {
        # By default just select an empty string
        $select = "''";

        # If an array of fields have been passed
        if (is_array($fields)) {

            # If we have some fields, then add them to the query, ensuring they are quoted appropriately
            if (count($fields) > 0) {
                $select = "";

                foreach ($fields as $field) {
                    if ($select) {
                        $select .= ", ";
                    }
                    $select .= $this->quoteField($field);
                }
            }

        # if the fields isn't an array
        } elseif (!is_bool($fields)) {
            # Otherwise assume it is a string of fields to select and add them to the query
            if (strlen($fields) > 0) {
                $select = $fields;
            }
        }

        return $select;
    }
591398
protected function getExcludeFiltersComponent(SearchQuery $searchQuery)
    {
        $fq = array();
        foreach ($searchQuery->exclude as $field => $values) {
            // Handle namespaced class names
            $field = $this->sanitiseClassName($field);

            $excludeq = [];
            $missing = false;

            foreach ($values as $value) {
                if ($value === SearchQuery::$missing) {
                    $missing = true;
                } elseif ($value === SearchQuery::$present) {
                    $excludeq[] = "{$field}:[* TO *]";
                } elseif ($value instanceof SearchQuery_Range) {
                    $start = $value->start;
                    if ($start === null) {
                        $start = '*';
                    }
                    $end = $value->end;
                    if ($end === null) {
                        $end = '*';
                    }
                    $excludeq[] = "$field:[$start TO $end]";
                } else {
                    $excludeq[] = $field . ':"' . $value . '"';
                }
            }

            $fq[] = ($missing ? "+{$field}:[* TO *] " : '') . '-(' . implode(' ', $excludeq) . ')';
        }
        return $fq;
    }
591113
public function buildSelectFields($fields)
    {
        $selectFields = [];
        foreach ((array)$fields as $key => $value) {
            if (is_int($key)) {
                $selectFields[$value] = true;
            } else {
                $selectFields[$key] = is_scalar($value) ? (bool)$value : $value;
            }
        }
        return $selectFields;
    }
1026570
public function searchOne(array $criterias = array())
    {
        $results = $this->search($criterias, 1);

        if (count($results) !== 1) {
            return null;
        }

        return $results[0];
    }
90254
public function findArray(Search $search)
    {
        $results = $this->executeSearch($search);

        return new ArrayIterator(
            $results,
            $this->getManager(),
            $this->getScrollConfiguration($results, $search->getScroll())
        );
    }