*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once '../vendor/autoload.php';
require_once __DIR__ . '/schemas/PubSchema.php';
try {
    // We'll need an index
    $obj_index = new \Search\Index('pubs');
    // Schema
    $obj_pub_schema = new PubSchema();
    // First pub
    $obj_pub1 = $obj_pub_schema->createDocument(['name' => 'Euston Tap', 'location' => [51.5269059, -0.1325679], 'rating' => 5]);
    // Second pub
    $obj_pub2 = $obj_pub_schema->createDocument(['name' => 'Kim by the Sea', 'location' => [53.4653381, -2.2483717], 'rating' => 3]);
    // Insert
    $obj_index->put([$obj_pub1, $obj_pub2]);
    echo "OK";
} catch (\Exception $obj_ex) {
    echo $obj_ex->getMessage();
    syslog(LOG_CRIT, $obj_ex->getMessage());
}
<?php

/**
 * Copyright 2015 Tom Walder
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once '../vendor/autoload.php';
require_once __DIR__ . '/schemas/BookSchema.php';
try {
    // Create Book (pre-defined Schema class)
    $obj_book_schema = new BookSchema();
    $obj_book = $obj_book_schema->createDocument(['title' => 'Romeo and Juliet', 'author' => 'William Shakespeare', 'isbn' => '1840224339', 'price' => 9.99]);
    // Insert - we'll need an index
    $obj_index = new \Search\Index('library');
    $obj_index->put($obj_book);
    echo "OK";
} catch (\Exception $obj_ex) {
    echo $obj_ex->getMessage();
    syslog(LOG_CRIT, $obj_ex->getMessage());
}
<?php

/**
 * Copyright 2015 Tom Walder
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once '../vendor/autoload.php';
require_once __DIR__ . '/schemas/PersonSchema.php';
try {
    // We'll need an index
    $obj_index = new \Search\Index('friends');
    // Schema
    $obj_person_schema = new PersonSchema();
    // Insert
    $obj_index->put($obj_person_schema->createDocument(['name' => 'Marty McFly Jnr', 'age' => 0, 'dob' => new DateTime()]));
    echo "OK";
} catch (\Exception $obj_ex) {
    echo $obj_ex->getMessage();
    syslog(LOG_CRIT, $obj_ex->getMessage());
}
예제 #4
0
 /**
  * Test the delete document function failure
  *
  * @expectedException        InvalidArgumentException
  * @expectedExceptionMessage Parameter must be one or more \Search\Document objects
  */
 public function testDeleteFailureArray()
 {
     $obj_index = new \Search\Index('test');
     $obj_index->delete(['abc', 123]);
 }
 /**
  * Test a basic put call
  *
  * @todo Expand range of field types
  */
 public function testPut()
 {
     $str_index = 'library';
     // Schema describing a book
     $obj_schema = (new \Search\Schema())->addText('title');
     // Create and populate a document
     $obj_book = $obj_schema->createDocument(['title' => 'The Merchant of Venice']);
     // Prepare the proxy mock
     $obj_request = new \google\appengine\IndexDocumentRequest();
     $obj_params = $obj_request->mutableParams();
     $obj_params->mutableIndexSpec()->setName($str_index);
     $obj_doc = $obj_params->addDocument();
     $obj_doc->addField()->setName('title')->mutableValue()->setType(storage_onestore_v3\FieldValue\ContentType::TEXT)->setStringValue('The Merchant of Venice');
     $this->apiProxyMock->expectCall('search', 'IndexDocument', $obj_request, new \google\appengine\IndexDocumentResponse());
     // Write it to the Index
     $obj_index = new \Search\Index($str_index);
     $obj_index->put($obj_book);
     $this->apiProxyMock->verify();
 }