<commit_before><?php

// Sets up a basic schema, adds a record, searches for the record

require  __DIR__ . '/vendor/autoload.php';

include_once "ExampleUtils.php";

use \Sajari\Field;
use \Sajari\Query\Request;

$client = new \Sajari\Client(getenv("SJ_PROJECT"), getenv("SJ_COLLECTION"), [
    new \Sajari\WithKeyCredentials(getenv("SJ_KEY_ID"), getenv("SJ_KEY_SECRET"))
]);

$fields = [
    Field::string("title")->setIndexed(true),
    Field::string("slug"),
    Field::boolean("draft"),
    Field::string("body")->setIndexed(true),
    Field::string("tags")->setRepeated(true),
    Field::timestamp("datecreated"),
    Field::integer("views")
];

// Set up schema
$resp = $client->schema()->addFields($fields);
foreach ($resp as $i => $status) {
    if (!$status->isOK()) {
        printf("error adding field %s: %s\n", $fields[$i]->getName(), $status);
    }
}

// Add records
list($keys, $statuses) = $client->addMulti([
    [
        "title" => "My holiday story",
        "slug" => "my-holiday-story",
        "draft" => "false",
        "body" => "My holiday began with...",
        "tags" => ["holiday", "story"],
        "datecreated" => new DateTime(),
        "views" => 100, // If only it were that easy..
    ],
    [
        "title" => "The new neighbours",
        "slug" => "the-new-neighbours",
        "draft" => "true",
        "body" => "Let me tell you about the new neighbours...",
        "tags" => ["neighbours", "local"],
        "datecreated" => new DateTime(),
        "views" => 0,
    ]
]);
foreach ($statuses as $i => $status) {
    if (!$status->isOK()) {
        printf("error adding record %d: %s", $i, $status);
    }
}

// Search
$results = $client->search(new Request("Holiday"))

// Print the results.
ExampleUtils::PrintSearchResults($results);
<commit_msg>examples: fix syntax bug in example<commit_after><?php

// Sets up a basic schema, adds a record, searches for the record

require  __DIR__ . '/vendor/autoload.php';

include_once "ExampleUtils.php";

use \Sajari\Field;
use \Sajari\Query\Request;

$client = new \Sajari\Client(getenv("SJ_PROJECT"), getenv("SJ_COLLECTION"), [
    new \Sajari\WithKeyCredentials(getenv("SJ_KEY_ID"), getenv("SJ_KEY_SECRET"))
]);

$fields = [
    Field::string("title")->setIndexed(true),
    Field::string("slug"),
    Field::boolean("draft"),
    Field::string("body")->setIndexed(true),
    Field::string("tags")->setRepeated(true),
    Field::timestamp("datecreated"),
    Field::integer("views")
];

// Set up schema
$resp = $client->schema()->addFields($fields);
foreach ($resp as $i => $status) {
    if (!$status->isOK()) {
        printf("error adding field %s: %s\n", $fields[$i]->getName(), $status);
    }
}

// Add records
list($keys, $statuses) = $client->addMulti([
    [
        "title" => "My holiday story",
        "slug" => "my-holiday-story",
        "draft" => "false",
        "body" => "My holiday began with...",
        "tags" => ["holiday", "story"],
        "datecreated" => new DateTime(),
        "views" => 100, // If only it were that easy..
    ],
    [
        "title" => "The new neighbours",
        "slug" => "the-new-neighbours",
        "draft" => "true",
        "body" => "Let me tell you about the new neighbours...",
        "tags" => ["neighbours", "local"],
        "datecreated" => new DateTime(),
        "views" => 0,
    ]
]);
foreach ($statuses as $i => $status) {
    if (!$status->isOK()) {
        printf("error adding record %d: %s", $i, $status);
    }
}

// Search
$results = $client->search(new Request("Holiday"));

// Print the results.
ExampleUtils::PrintSearchResults($results);

{'fraction_non_alphanumeric': 0.20502901353965183, 'fraction_numerical': 0.0022105554020447637, 'mean_word_length': 3.1513761467889907, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4853504', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1202, 'n_words': 275}