Git Product home page Git Product logo

cakephp-cloud-search's Introduction

cakephp-cloud-search

Amazon CloudSearch DataSource Plugin for CakePHP

Requirements

Installation

cd app/Plugin
git clone [email protected]: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)

cakephp-cloud-search's People

Contributors

violetyk avatar

Watchers

James Cloos avatar Francisco Velazquez avatar

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.