FoolCode / SphinxQL-Query-Builder

SphinxQL Query Builder generates SphinxQL, a SQL dialect, which is used to query the Sphinx search engine. (Composer Package)
http://foolcode.github.com/SphinxQL-Query-Builder/
326 stars 95 forks source link

Inserting MVA Attrubutes #178

Open KarelWintersky opened 5 years ago

KarelWintersky commented 5 years ago

Add to FAQ / ReadME

class SBSearch { 
...
... somewhere above is init() method

public static function createConnection()
    {
        $conn = new Connection();
        $conn->setParams([
            'host' => self::$sphinx_connection_host,
            'port' => self::$sphinx_connection_port
        ]);

        return (new SphinxQL($conn));
    }

public static function rt_ReplaceIndex(string $index_name, array $updateset)
    {
        if (empty($updateset)) return null;

        return self::createConnection()
            ->replace()
            ->into($index_name)
            ->set($updateset)
            ->execute();
 }
...

I am adding data to my index.

$dataset = [
                'id'            =>  $id,
                'title'         =>  $item['title'],
                'short'         =>  $item['short'],
                'text'          =>  $item['text_bb'],

                'date_added'    =>  date_format( date_create_from_format('Y-m-d H:i:s', $item['cdate']), 'U' ),

                'type'          =>  1,
                'photo'         =>  ((@$item['photo']['file'] != "") ? 1 : 0),
                'author'        =>  $item['author'],

                'districts_all' =>  $item['districts_all'],
            ];

            $status = SBSearch::rt_ReplaceIndex($sphinx_target_index, $dataset);

How to add MVA attribute 'rubrics' and 'districts'? This fields described as

rt_attr_multi           = rubrics
rt_attr_multi           = districts

Easy:

'rubrics'       =>  array_keys($item['rubrics']),
'districts'     =>  array_keys($item['districts'])

Just send to dataset field ARRAY of values.

oohnoitz commented 5 years ago

Not sure what the ask is. I think adding a single line under https://github.com/FoolCode/SphinxQL-Query-Builder#insert-replace mentioning MVA attribute support would be enough. Would welcome a PR for it.

KarelWintersky commented 5 years ago

it is not a PR. but a HINT for someone looking answer for this