Code Monkey home page Code Monkey logo

yii2-search's Introduction

Search in Active Record models for Yii2

Build Status Scrutinizer Code Quality Total Downloads Latest Stable Version Latest Unstable Version

This is component for searching in the Active Record models for Yii2 Framework.

Documentation is at docs/guide/README.md.

Installation

Install package

The preferred way to install this extension is through composer.

Either run

$ composer require vintage/yii2-search

or add

"vintage/yii2-search": "~2.0"

to the require section of your composer.json.

Usage

Implement \vintage\search\interfaces\SearchInterface interface in Active Record models

/**
 * Article search model.
 * 
 * @property integer $id
 * @property string $title
 * @property string $short_description
 * @property string $content
 */
class ArticleSearch extends ActiveRecord implements \vintage\search\interfaces\SearchInterface
{
    /**
     * @inheritdoc
     */
    public function getSearchTitle()
    {
    
        return $this->title;
    }

    /**
     * @inheritdoc
     */
    public function getSearchDescription()
    {
        return $this->short_description;
    }

    /**
     * @inheritdoc
     */
    public function getSearchUrl()
    {
       return Url::toRoute(['/news/default/index', 'id' => $this->id]);
    }

   /**
    * @inheritdoc
    */
    public function getSearchFields()
    {
        return [
            'title',
            'short_description',
            'content',
        ];
    }
}

Call method of search component with a query

/* @var \vintage\search\models\SearchResult[] $result */
$result = Yii::$app->get('searcher')->search('some query here');

this method returns array of \vintage\search\models\SearchResult objects.

Tests

You can run tests with composer command

$ composer test

or using following command

$ codecept build && codecept run

Contributing

For information about contributing please read CONTRIBUTING.md.

Licence

License

This project is released under the terms of the BSD-3-Clause license.

yii2-search's People

Contributors

developer-av avatar greeflas avatar palyanitsaaa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

yii2-search's Issues

Дополнительные атрибуты

Здравствуйте. В результатах поиска мы получаем объекты класса vintage\search\modelsSearchResult. И у него есть атрибуты: title, description, url, modelId, modelName.
Как можно получить кастомные атрибуты, кроме выше перечисленных? К примеру я бы хотел получить атрибут image из моей модели.

adamdar local test 2018-05-28 12-20-35

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.