Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

'CustomEngine', an event based engine for searching #334

Open
timgws opened this issue Sep 9, 2015 · 1 comment
Open

'CustomEngine', an event based engine for searching #334

timgws opened this issue Sep 9, 2015 · 1 comment
Assignees
Labels
Milestone

Comments

@timgws
Copy link
Collaborator

timgws commented Sep 9, 2015

I am thinking that an event driven CustomEngine might not be a bad idea.

At the moment I have a bunch of data that is sitting in Elasticsearch (which represents a few million rows inside my MySQL db).

If I was able to have an event driven engine, then I could specify with a callback the variables I need to:

  1. Search
  2. Order
  3. Filter/Limit

Then inside the CustomEngine, I could either return the data, or alternatively, provide another callback to retrieve the data that I want to show inside the Datatable.

I imagine using it similar to:

use \Chumper\Datatable\Datatable;
use \Chumper\Datatable\DatatableQuery;


class ComplexDatatableController {
    public function getDatatable() {
        $dt = new Datatable();

        return $dt->custom(
            function (DatatableQuery $filter) {
                return $elasticsearch->find($filter->searchString)->getIndexID();
            },
            function (DatatableResults $results) {
                return $mysql->findByID($results->getArray());
            })
            ->showColumns('id', 'name', 'description')
            ->searchColumns('name', 'description')
            ->orderColumns('id','name', 'description')
            ->make();
    }
}

The CustomEngine would have two parameters on the class, a filter, and a results processor. If the second parameter is left null, it is assumed that the filter will also return the results that will be used by the Datatables VersionResponse. Otherwise, it is assumed that the filter will just return IDs/other references that can be used to grab the results.

Where the DatatableQuery would have all the values of the query (implementing an interface similar to #333?)

    class DatatableQuery
    {

        /** @var bool do we need to search on columns, or just order & filter? */
        public $searchColumns = false;

        /** @var bool are we using a plugin to search individual plugins */
        public $searchIndividualColumns = true;

        /** @var string The string we are searching for (note: for searchColumns) */
        public $searchString = '';

        /** @var array the columns that we are searching, the content that has been put in */
        public $searchColumn = [];

        /** @var bool the search is a regular expression */
        public $searchRegex = true;

        /** @var int the number of columns we are showing in the datatable */
        public $numberOfColumns = 0;

        /** @var array a list of all the columns we are showing */
        public $columns = [];

        /** @var array a list of the columns we are sorting by, with their direction */
        /* [    [ 'id' => 'desc' ], [ 'name', 'asc' ]    ] */
        public $order = [];

        /** @var int which result to start from */
        public $start = 0;

        /** @var int the limit of the result. */
        public $limit = 0;
    }
@timgws timgws added the question label Sep 9, 2015
@timgws timgws self-assigned this Sep 9, 2015
@timgws timgws added this to the 5.0 milestone Sep 9, 2015
@timgws
Copy link
Collaborator Author

timgws commented Sep 10, 2015

Actually, I was thinking it might be a little better (and a tad more obvious) if this was called MapReduceEngine.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant