コード例 #1
0
ファイル: SearchIndex.php プロジェクト: nresni/Ariadne
    /**
     * Transforms a generic Query object into an Elastic Search query DSL
     *
     * @param Query $query
     */
    public function mapQuery(Query $query)
    {
        $arguments = array();

        $map = new Boolean();

        if ($query->hasQueryString()) {

            Lucene::setDefaultSearchField($query->getQueryString()->getDefaultField());

            QueryParser::setDefaultOperator($query->getQueryString()->getDefaultOperator() == Query::OPERATOR_AND ? QueryParser::B_AND : QueryParser::B_OR);

            $keyword = $query->getQueryString()->getQuery();

            if ("*" === $keyword) {
                $subQuery = new Wildcard(new Term($keyword));
                $subQuery->setMinPrefixLength(0);
            } else {
                $subQuery = QueryParser::parse($keyword);
            }

            $map->addSubquery($subQuery, true);
        }

        $arguments[] = $map;

        foreach ($query->getSort() as $sort) {
            $arguments[] = key($sort);
            $arguments[] = SORT_REGULAR;
            $arguments[] = current($sort) == 'asc' ? SORT_ASC : SORT_DESC;
        }

        return $arguments;
    }
コード例 #2
0
ファイル: SearchIndex.php プロジェクト: nresni/Ariadne
    /**
     * Transforms a generic Query object into an Elastic Search query DSL
     *
     * @param Query $query
     */
    public function mapQuery(Query $query)
    {
        $map['from'] = $query->getOffset();
        $map['size'] = $query->getLimit();

        if ($query->hasQueryString()) {
            $map['query']['query_string'] = array();
            $map['query']['query_string']['query'] = $query->getQueryString()->getQuery();
            $map['query']['query_string']['default_field'] = $query->getQueryString()->getDefaultField();
            $map['query']['query_string']['default_operator'] = $query->getQueryString()->getDefaultOperator() == Query::OPERATOR_AND ? 'and' : 'or';
        }

        foreach ($query->getSort() as $sort) {
            $map['sort'][] = $sort;
        }

        return $map;
    }
コード例 #3
0
ファイル: SearchManager.php プロジェクト: nresni/Ariadne
    /**
     * Executes a query against the given class name's index
     *
     * @param string class name
     * @return Response $response
     */
    public function search(Query $query)
    {
        $metadata = $this->getClassMetadata($query->getClassName());

        return $this->adapter->search($metadata, $query);
    }