<commit_before><?php
/*
 * Copyright (c) 2013 Algolia
 * http://www.algolia.com/
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 *
 * VERSION 1.2.2
 *
 */
namespace AlgoliaSearch;

/*
 * Contains all the functions related to one index
 * You should use Client.initIndex(indexName) to retrieve this object
 */
class Index {

    private $indexName;
    private $client;
    private $urlIndexName;
    private $curlHandle;

    /*
     * Index initialization (You should not call this initialized yourself)
     */
    public function __construct($context, $client, $indexName) {
        $this->context = $context;
        $this->client = $client;
        $this->indexName = $indexName;
        $this->urlIndexName = urlencode($indexName);
    }

    /*
     * Perform batch operation on several objects
     *
     * @param objects contains an array of objects to update (each object must contains an objectID attribute)
     * @param objectIDKey  the key in each object that contains the objectID
     * @param objectActionKey  the key in each object that contains the action to perform (addObject, updateObject, deleteObject or partialUpdateObject)
     */
    public function batchObjects($objects, $objectIDKey = "objectID", $objectActionKey = "objectAction") {
        $requests = array();

        foreach ($objects as $obj) {
            // If no or invalid action, assume updateObject
            if (! isset($obj[$objectActionKey]) || ! in_array($obj[$objectActionKey], array('addObject', 'updateObject', 'deleteObject', 'partialUpdateObject'))) {
                $obj[$objectActionKey] = 'updateObject';
            }

            $action = $obj[$objectActionKey];
            unset($obj[$objectActionKey]); // The action key is not included in the object

            $req = array("action" => $action, "body" => $obj);

            if (array_key_exists($objectIDKey, $obj)) {
                $req["objectID"] = (string) $obj[$objectIDKey];
            }

            $requests[] = $req;
        }

        return $this->batch(array("requests" => $requests));
    }

    /*
     * Add an object in this index
     *
     * @param content contains the object to add inside the index.
     *  The object is represented by an associative array
     * @param objectID (optional) an objectID you want to attribute to this object
     * (if the attribute already exist the old object will be overwrite)
     */
    public function addObject($content, $objectID = null) {

        if ($objectID === null) {
            return $this->client->request($this->context, "POST", "/1/indexes/" . $this->urlIndexName, array(), $content);
        } else {<commit_msg>Remove automatic affectation of updateObject on batchObjects<commit_after><?php
/*
 * Copyright (c) 2013 Algolia
 * http://www.algolia.com/
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 *
 * VERSION 1.2.2
 *
 */
namespace AlgoliaSearch;

/*
 * Contains all the functions related to one index
 * You should use Client.initIndex(indexName) to retrieve this object
 */
class Index {

    private $indexName;
    private $client;
    private $urlIndexName;
    private $curlHandle;

    /*
     * Index initialization (You should not call this initialized yourself)
     */
    public function __construct($context, $client, $indexName) {
        $this->context = $context;
        $this->client = $client;
        $this->indexName = $indexName;
        $this->urlIndexName = urlencode($indexName);
    }

    /*
     * Perform batch operation on several objects
     *
     * @param objects contains an array of objects to update (each object must contains an objectID attribute)
     * @param objectIDKey  the key in each object that contains the objectID
     * @param objectActionKey  the key in each object that contains the action to perform (addObject, updateObject, deleteObject or partialUpdateObject)
     */
    public function batchObjects($objects, $objectIDKey = "objectID", $objectActionKey = "objectAction") {
        $requests = array();

        foreach ($objects as $obj) {
            // If no or invalid action, assume updateObject
            if (! isset($obj[$objectActionKey]) || ! in_array($obj[$objectActionKey], array('addObject', 'updateObject', 'deleteObject', 'partialUpdateObject', 'partialUpdateObjectNoCreate'))) {
                throw new \Exception('invalid or no action detected');
            }

            $action = $obj[$objectActionKey];
            unset($obj[$objectActionKey]); // The action key is not included in the object

            $req = array("action" => $action, "body" => $obj);

            if (array_key_exists($objectIDKey, $obj)) {
                $req["objectID"] = (string) $obj[$objectIDKey];
            }

            $requests[] = $req;
        }

        return $this->batch(array("requests" => $requests));
    }

    /*
     * Add an object in this index
     *
     * @param content contains the object to add inside the index.
     *  The object is represented by an associative array
     * @param objectID (optional) an objectID you want to attribute to this object
     * (if the attribute already exist the old object will be overwrite)
     */
    public function addObject($content, $objectID = null) {

        if ($objectID === null) {
            return $this->client->request($this->context, "POST", "/1/indexes/" . $this->urlIndexName, array(), $content);
        } else {
{'fraction_non_alphanumeric': 0.09673534921059673, 'fraction_numerical': 0.0021407546160021407, 'mean_word_length': 3.060293318848452, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4122656', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1881, 'n_words': 794}