Skip to content

somnathpzalte/cakephp-cloud-search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cakephp-cloud-search

Amazon CloudSearch DataSource Plugin for CakePHP

Requirements

Installation

cd app/Plugin
git clone git@github.com:nanapi/cakephp-cloud-search.git CloudSearch

app/Config/bootstrap.php

CakePlugin::load('CloudSearch');

app/Config/database.php

<?php

class DATABASE_CONFIG {

  public $cloud_search = [
    'datasource' => 'CloudSearch.CloudSearchSource',
    'key'        => 'AWS_ACCESS_KEY_HERE',
    'secret'     => 'AWS_SECRET_HERE',
    'region'     => 'REGION',
  ];

How to use it

your model

<?php

App::uses('CloudSearchModel', 'CloudSearch.Model');
class MyModel extends CloudSearchModel {
  public $useTable  = 'DOMAIN';
}

your controller

<?php
App::uses('AppController', 'Controller');
class MyController extends AppController {
  public $uses = [
    'MyModel';
  ];

  public function index() {
    // save
    $save_data = $this->MyModel->create();
    $save_data = [
      'id' => 'unique_id',
      'fields' => [
        'index_name1' => 'value1'
        'index_name2' => ['value2', 'value3']
      ]
    ];
    $this->MyModel->save($save_data);

    // find
    $result = $this->MyModel>find('all', [
      'conditions' => [
        'query' => 'value1|value2'
      ],
      'fields' => [
        'id',
        'name',
        '_score'
      ]
    ]);

    // pagination and using facet
    $options = [
      'conditions' => [
        'query' => "(and user_id:3 (or subject:'word1 word2' contents:'word1 word2'))",
        'sort' => '_score desc',
        'queryParser' => 'structured',
      ],
      'facet' => [
        'user_name' => ['size' => 10],
        'category' => ['size' => 20],
        ],
      'limit' => 50,
    ];
    $this->Paginator->settings = $options;
    $records = $this->Paginator->paginate('MyModel');
    $facets = $this->MyModel->getFacets();


    // delete
    $id = 'unique_id';
    $this->MyModel->delete($id);

    $this->MyModel->deleteAll([
      'MyModel.id' => ['unique_id_1', 'unique_id_2', 'unique_id_3'],
    ]);
  }

ToDo

  • query method (findBy)

About

Amazon CloudSearch DataSource Plugin for CakePHP

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages