<commit_before><?php
/**
 * Copyright (c) 2001-2012, <NAME>
 * Copyright (c) 2008-2012, Sphinx Technologies Inc
 * All rights reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License. You should have
 * received a copy of the GPL license along with this program; if you
 * did not, you can find it at http://www.gnu.org/
 */

namespace NilPortugues\Sphinx;

/**
 * Known searchd commands.
 */
define ( "SEARCHD_COMMAND_SEARCH",		0 );
define ( "SEARCHD_COMMAND_EXCERPT",		1 );
define ( "SEARCHD_COMMAND_UPDATE",		2 );
define ( "SEARCHD_COMMAND_KEYWORDS",	3 );
define ( "SEARCHD_COMMAND_PERSIST",		4 );
define ( "SEARCHD_COMMAND_STATUS",		5 );
define ( "SEARCHD_COMMAND_FLUSHATTRS",	7 );

/**
 * Current client-side command implementation versions.
 */
define ( "VER_COMMAND_SEARCH",		0x119 );
define ( "VER_COMMAND_EXCERPT",		0x104 );
define ( "VER_COMMAND_UPDATE",		0x102 );
define ( "VER_COMMAND_KEYWORDS",	0x100 );
define ( "VER_COMMAND_STATUS",		0x100 );
define ( "VER_COMMAND_QUERY",		0x100 );
define ( "VER_COMMAND_FLUSHATTRS",	0x100 );

/**
 * Known searchd status codes.
 */
define ( "SEARCHD_OK",				0 );
define ( "SEARCHD_ERROR",			1 );
define ( "SEARCHD_RETRY",			2 );
define ( "SEARCHD_WARNING",			3 );

/**
 * Known match modes.
 */
define ( "SPH_MATCH_ALL",			0 );
define ( "SPH_MATCH_ANY",			1 );
define ( "SPH_MATCH_PHRASE",		2 );
define ( "SPH_MATCH_BOOLEAN",		3 );
define ( "SPH_MATCH_EXTENDED",		4 );
define ( "SPH_MATCH_FULLSCAN",		5 );
define ( "SPH_MATCH_EXTENDED2",		6 );	// extended engine V2 (TEMPORARY, WILL BE REMOVED)

/**
 * Known ranking modes (ext2 only).
 */
define ( "SPH_RANK_PROXIMITY_BM25",	0 );	// default mode, phrase proximity major factor and BM25 minor one
define ( "SPH_RANK_BM25",			1 );	// statistical mode, BM25 ranking only (faster but worse quality)
define ( "SPH_RANK_NONE",			2 );	// no ranking, all matches get a weight of 1
define ( "SPH_RANK_WORDCOUNT",		3 );	// simple word-count weighting, rank is a weighted sum of per-field keyword occurrence counts
define ( "SPH_RANK_PROXIMITY",		4 );
define ( "SPH_RANK_MATCHANY",		5 );
define ( "SPH_RANK_FIELDMASK",		6 );
define ( "SPH_RANK_SPH04",			7 );
define ( "SPH_RANK_EXPR",			8 );
define ( "SPH_RANK_TOTAL",			9 );

/**
 * Known sort modes.
 */
define ( "SPH_SORT_RELEVANCE",		0 );
define ( "SPH_SORT_ATTR_DESC",		1 );
define ( "SPH_SORT_ATTR_ASC",		2 );
define ( "SPH_SORT_TIME_SEGMENTS", 	3 );
define ( "SPH_SORT_EXTENDED", 		4 );
define ( "SPH_SORT_EXPR", 			5 );

/**
 * Known filter types.
 */
define ( "SPH_FILTER_VALUES",		0 );
define ( "SPH_FILTER_RANGE",		1 );
define ( "SPH_FILTER_FLOATRANGE",	2 );

/**
 * Known attribute types.
 */
define ( "SPH_ATTR_INTEGER",		1 );
define ( "SPH_ATTR_TIMESTAMP",		2 );
define ( "SPH_ATTR_ORDINAL",		3 );
define ( "SPH_ATTR_BOOL",			4 );
define ( "SPH_ATTR_FLOAT",			5 );
define ( "SPH_ATTR_BIGINT",			6 );
define ( "SPH_ATTR_STRING",			7 );
define ( "SPH_ATTR_MULTI",			0x40000001 );
define ( "SPH_ATTR_MULTI64",        0x40000002 );

/**
 * Known grouping functions.
 */
define ( "SPH_GROUPBY_DAY",			0 );
define ( "SPH_GROUPBY_WEEK",		1 );
define ( "SPH_GROUPBY_MONTH",		2 );
define ( "SPH_GROUPBY_YEAR",		3 );
define ( "SPH_GROUPBY_ATTR",		4 );
define ( "SPH_GROUPBY_ATTRPAIR",	5 );

/**
 * PHP version of Sphinx searchd client.
 *
 * @author <NAME> <<EMAIL>>
 */
class SphinxClient
{
    protected $_host;           // searchd host (default is "localhost")
    protected $_port;           // searchd port (default is 9312)
    protected $_offset;         // how many records to seek from result-set start (default is 0)
    protected $_limit;          // how many records to return from result-set starting at offset (default is 20)
    protected $_mode;           // query matching mode (default is SPH_MATCH_ALL)
    protected $_weights;        // per-field weights (default is 1 for all fields)
    protected $_sort;           // match sorting mode (default is SPH_SORT_RELEVANCE)
    protected $_sortby;         // attribute to sort by (defualt is "")
    protected $_min_id;         // min ID to match (default is 0, which means no limit)
    protected $_max_id;         // max ID to match (default is 0, which means no limit)
    protected $_filters;        // search filters
    protected $_groupby;        // group-by attribute name
    protected $_groupfunc;      // group-by function (to pre-process group-by attribute value with)
    protected $_groupsort;      // group-by sorting clause (to sort groups in result set with)
    protected $_groupdistinct;  // group-by count-distinct attribute
    protected $_maxmatches;     // max matches to retrieve
    protected $_cutoff;         // cutoff to stop searching at (default is 0)
    protected $_retrycount;     // distributed retries count
    protected $_retrydelay;     // distributed retries delay
    protected $_anchor;         // geographical anchor point
    protected $_indexweights;   // per-index weights
    protected $_ranker;         // ranking mode (default is SPH_RANK_PROXIMITY_BM25)
    protected $_rankexpr;       // ranking mode expression (for SPH_RANK_EXPR)
    protected $_maxquerytime;   // max query time, milliseconds (default is 0, do not limit)
    protected $_fieldweights;   // per-field-name weights
    protected $_overrides;      // per-query attribute values overrides
    protected $_select;         // select-list (attributes or expressions, with optional aliases)
    protected $_error;          // last error message
    protected $_warning;        // last warning message
    protected $_connerror;      // connection error vs remote error flag
    protected $_reqs;           // requests array for multi-query
    protected $_mbenc;          // stored mbstring encoding
    protected $_arrayresult;    // whether $result["matches"] should be a hash or an array
    protected $_timeout;        // connect timeout
    protected $_path;
    protected $_socket;

    /**
     * Creates a new client object and fill defaults
     */
    public function __construct()
    {
        // Per-client-object settings
        $this->_host		    = "localhost";
        $this->_port		    = 9312;
        $this->_path		    = false;
        $this->_socket		    = false;

        // Per-query settings
        $this->_offset		    = 0;
        $this->_limit		    = 20;
        $this->_mode		    = SPH_MATCH_ALL;
        $this->_weights		    = array ();
        $this->_sort		    = SPH_SORT_RELEVANCE;
        $this->_sortby		    = "";
        $this->_min_id		    = 0;
        $this->_max_id		    = 0;
        $this->_filters		    = array ();
        $this->_groupby		    = "";
        $this->_groupfunc	    = SPH_GROUPBY_DAY;
        $this->_groupsort	    = "@group desc";
        $this->_groupdistinct   = "";
        $this->_maxmatches	    = 1000;
        $this->_cutoff		    = 0;
        $this->_retrycount	    = 0;
        $this->_retrydelay	    = 0;
        $this->_anchor		    = array ();
        $this->_indexweights    = array ();
        $this->_ranker		    = SPH_RANK_PROXIMITY_BM25;
        $this->_rankexpr	    = "";
        $this->_maxquerytime    = 0;
        $this->_fieldweights    = array();<commit_msg>Fixing tabulations<commit_after><?php
/**
 * @author: <NAME>
 * Copyright (c) 2001-2012, <NAME>
 * Copyright (c) 2008-2012, Sphinx Technologies Inc
 * All rights reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License. You should have
 * received a copy of the GPL license along with this program; if you
 * did not, you can find it at http://www.gnu.org/
 */

namespace NilPortugues\Sphinx;

/**
 * Known searchd commands.
 */
define ( "SEARCHD_COMMAND_SEARCH",0 );
define ( "SEARCHD_COMMAND_EXCERPT",1 );
define ( "SEARCHD_COMMAND_UPDATE",2 );
define ( "SEARCHD_COMMAND_KEYWORDS",3 );
define ( "SEARCHD_COMMAND_PERSIST",4 );
define ( "SEARCHD_COMMAND_STATUS",5 );
define ( "SEARCHD_COMMAND_FLUSHATTRS",7 );

/**
 * Current client-side command implementation versions.
 */
define ( "VER_COMMAND_SEARCH",0x119 );
define ( "VER_COMMAND_EXCERPT",0x104 );
define ( "VER_COMMAND_UPDATE",0x102 );
define ( "VER_COMMAND_KEYWORDS",0x100 );
define ( "VER_COMMAND_STATUS",0x100 );
define ( "VER_COMMAND_QUERY",0x100 );
define ( "VER_COMMAND_FLUSHATTRS",0x100 );

/**
 * Known searchd status codes.
 */
define ( "SEARCHD_OK",0 );
define ( "SEARCHD_ERROR",1 );
define ( "SEARCHD_RETRY",2 );
define ( "SEARCHD_WARNING",3 );

/**
 * Known match modes.
 */
define ( "SPH_MATCH_ALL",0 );
define ( "SPH_MATCH_ANY",1 );
define ( "SPH_MATCH_PHRASE",2 );
define ( "SPH_MATCH_BOOLEAN",3 );
define ( "SPH_MATCH_EXTENDED",4 );
define ( "SPH_MATCH_FULLSCAN",5 );
define ( "SPH_MATCH_EXTENDED2",6 );	// extended engine V2 (TEMPORARY, WILL BE REMOVED)

/**
 * Known ranking modes (ext2 only).
 */
define ( "SPH_RANK_PROXIMITY_BM25",0 );	// default mode, phrase proximity major factor and BM25 minor one
define ( "SPH_RANK_BM25",1 );	// statistical mode, BM25 ranking only (faster but worse quality)
define ( "SPH_RANK_NONE",2 );	// no ranking, all matches get a weight of 1
define ( "SPH_RANK_WORDCOUNT",3 );	// simple word-count weighting, rank is a weighted sum of per-field keyword occurrence counts
define ( "SPH_RANK_PROXIMITY",4 );
define ( "SPH_RANK_MATCHANY",5 );
define ( "SPH_RANK_FIELDMASK",6 );
define ( "SPH_RANK_SPH04",7 );
define ( "SPH_RANK_EXPR",8 );
define ( "SPH_RANK_TOTAL",9 );

/**
 * Known sort modes.
 */
define ( "SPH_SORT_RELEVANCE",0 );
define ( "SPH_SORT_ATTR_DESC",1 );
define ( "SPH_SORT_ATTR_ASC",2 );
define ( "SPH_SORT_TIME_SEGMENTS",3 );
define ( "SPH_SORT_EXTENDED",4 );
define ( "SPH_SORT_EXPR",5 );

/**
 * Known filter types.
 */
define ( "SPH_FILTER_VALUES",0 );
define ( "SPH_FILTER_RANGE",1 );
define ( "SPH_FILTER_FLOATRANGE",2 );

/**
 * Known attribute types.
 */
define ( "SPH_ATTR_INTEGER",1 );
define ( "SPH_ATTR_TIMESTAMP",2 );
define ( "SPH_ATTR_ORDINAL",3 );
define ( "SPH_ATTR_BOOL",4 );
define ( "SPH_ATTR_FLOAT",5 );
define ( "SPH_ATTR_BIGINT",6 );
define ( "SPH_ATTR_STRING",7 );
define ( "SPH_ATTR_MULTI",0x40000001 );
define ( "SPH_ATTR_MULTI64",0x40000002 );

/**
 * Known grouping functions.
 */
define ( "SPH_GROUPBY_DAY",	0 );
define ( "SPH_GROUPBY_WEEK",1 );
define ( "SPH_GROUPBY_MONTH",2 );
define ( "SPH_GROUPBY_YEAR",3 );
define ( "SPH_GROUPBY_ATTR",4 );
define ( "SPH_GROUPBY_ATTRPAIR",5 );

/**
 * PHP version of Sphinx searchd client.
 *
 * @author <NAME> <<EMAIL>>
 */
class SphinxClient
{
    protected $_host;           // searchd host (default is "localhost")
    protected $_port;           // searchd port (default is 9312)
    protected $_offset;         // how many records to seek from result-set start (default is 0)
    protected $_limit;          // how many records to return from result-set starting at offset (default is 20)
    protected $_mode;           // query matching mode (default is SPH_MATCH_ALL)
    protected $_weights;        // per-field weights (default is 1 for all fields)
    protected $_sort;           // match sorting mode (default is SPH_SORT_RELEVANCE)
    protected $_sortby;         // attribute to sort by (defualt is "")
    protected $_min_id;         // min ID to match (default is 0, which means no limit)
    protected $_max_id;         // max ID to match (default is 0, which means no limit)
    protected $_filters;        // search filters
    protected $_groupby;        // group-by attribute name
    protected $_groupfunc;      // group-by function (to pre-process group-by attribute value with)
    protected $_groupsort;      // group-by sorting clause (to sort groups in result set with)
    protected $_groupdistinct;  // group-by count-distinct attribute
    protected $_maxmatches;     // max matches to retrieve
    protected $_cutoff;         // cutoff to stop searching at (default is 0)
    protected $_retrycount;     // distributed retries count
    protected $_retrydelay;     // distributed retries delay
    protected $_anchor;         // geographical anchor point
    protected $_indexweights;   // per-index weights
    protected $_ranker;         // ranking mode (default is SPH_RANK_PROXIMITY_BM25)
    protected $_rankexpr;       // ranking mode expression (for SPH_RANK_EXPR)
    protected $_maxquerytime;   // max query time, milliseconds (default is 0, do not limit)
    protected $_fieldweights;   // per-field-name weights
    protected $_overrides;      // per-query attribute values overrides
    protected $_select;         // select-list (attributes or expressions, with optional aliases)
    protected $_error;          // last error message
    protected $_warning;        // last warning message
    protected $_connerror;      // connection error vs remote error flag
    protected $_reqs;           // requests array for multi-query
    protected $_mbenc;          // stored mbstring encoding
    protected $_arrayresult;    // whether $result["matches"] should be a hash or an array
    protected $_timeout;        // connect timeout
    protected $_path;
    protected $_socket;

    /**
     * Creates a new client object and fill defaults
     */
    public function __construct()
    {
        // Per-client-object settings
        $this->_host		    = "localhost";
        $this->_port		    = 9312;
        $this->_path		    = false;
        $this->_socket		    = false;

        // Per-query settings
        $this->_offset		    = 0;
        $this->_limit		    = 20;
        $this->_mode		    = SPH_MATCH_ALL;
        $this->_weights		    = array ();
        $this->_sort		    = SPH_SORT_RELEVANCE;
        $this->_sortby		    = "";
        $this->_min_id		    = 0;
        $this->_max_id		    = 0;
        $this->_filters		    = array ();
        $this->_groupby		    = "";
        $this->_groupfunc	    = SPH_GROUPBY_DAY;
        $this->_groupsort       = "@group desc";
        $this->_groupdistinct   = "";
        $this->_maxmatches	    = 1000;
        $this->_cutoff		    = 0;
        $this->_retrycount	    = 0;
        $this->_retrydelay	    = 0;
        $this->_anchor		    = array ();
        $this->_indexweights    = array ();
        $this->_ranker		    = SPH_RANK_PROXIMITY_BM25;
        $this->_rankexpr	    = "";
        $this->_maxquerytime    = 0;
        $this->_fieldweights    = array();
{'fraction_non_alphanumeric': 0.12245040027845458, 'fraction_numerical': 0.02241559345631744, 'mean_word_length': 2.825832223701731, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 66, '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': '660217', 'n_tokens_mistral': 4909, 'n_tokens_neox': 4678, 'n_words': 1266}