Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metod match('word word2') generate query type AND #70

Open
Maxpl opened this issue Dec 21, 2021 · 5 comments
Open

Metod match('word word2') generate query type AND #70

Maxpl opened this issue Dec 21, 2021 · 5 comments

Comments

@Maxpl
Copy link

Maxpl commented Dec 21, 2021

In documentation OR as default operator
I try profile()->match('word word2') and i see :
[query] => Array
(
[type] => AND
[description] => AND( AND( AND(KEYWORD(word, querypos=1)), AND(KEYWORD(word2, querypos=2))), OR( AND(KEYWORD(word, querypos=1)), AND(KEYWORD(word2, querypos=2))))....

if i set
->math(['query' => 'word word2', 'operator' => 'or'])
has no effect.

@sanikolaev
Copy link
Collaborator

I can't reproduce it, please provide a full script. E.g.:

<?php
require_once __DIR__ . '/vendor/autoload.php';

use Manticoresearch\Client;
use Manticoresearch\Search;

$config = ['host'=>'127.0.0.1','port'=>9308];
$client = new \Manticoresearch\Client($config);
$index = $client->index('movies');

$params = [
   'index' => 'movies',
   ['body' => ['silent'=>true ]]
];
$client->indices()->drop($params);

$index->create([
    'title'=>['type'=>'text'],
    'plot'=>['type'=>'text'],
    'year'=>['type'=>'integer'],
    'rating'=>['type'=>'float']
    ]);

$index->addDocuments([
        ['id'=>2,'title'=>'Interstellar','plot'=>'A team of explorers travel through a wormhole in space in an attempt to ensure humanity\'s survival.','year'=>2014,'rating'=>8.5],
        ['id'=>3,'title'=>'Inception','plot'=>'A thief who steals corporate secrets through the use of dream-sharing technology is given the inverse task of planting an idea into the mind of a C.E.O.','year'=>2010,'rating'=>8.8],
        ['id'=>4,'title'=>'1917 ','plot'=>' As a regiment assembles to wage war deep in enemy territory, two soldiers are assigned to race against time and deliver a message that will stop 1,600 men from walking straight into a deadly trap.','year'=>2018,'rating'=>8.4],
        ['id'=>5,'title'=>'Alien','plot'=>' After a space merchant vessel receives an unknown transmission as a distress call, one of the team\'s member is attacked by a mysterious life form and they soon realize that its life cycle has merely begun.','year'=>1979,'rating'=>8.4]
    ]);

$search = new Search($client);
$search->setIndex('movies');

$results = $search->profile()->match('spaceddd team')->get();

print_r($results);

foreach($results as $doc) {
   echo 'Document:'.$doc->getId()."\n";
   foreach($doc->getData() as $field=>$value)
   {
        echo $field.": ".$value."\n";
   }
}
~ php test.php
Manticoresearch\ResultSet Object
(
    [position:protected] => 0
    [response:protected] => Manticoresearch\Response Object
        (
            [time:protected] => 0.00069093704223633
            [string:protected] => {"took":0,"timed_out":false,"hits":{"total":2,"hits":[{"_id":"5","_score":1528,"_source":{"year":1979,"rating":8.400000,"title":"Alien","plot":" After a space merchant vessel receives an unknown transmission as a distress call, one of the team's member is attacked by a mysterious life form and they soon realize that its life cycle has merely begun."}},{"_id":"2","_score":1528,"_source":{"year":2014,"rating":8.500000,"title":"Interstellar","plot":"A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival."}}]},"profile":{"query":{"type":"OR","description":"OR( AND(KEYWORD(spaceddd, querypos=1)),  AND(KEYWORD(team, querypos=2)))","children":[{"type":"AND","description":"AND(KEYWORD(spaceddd, querypos=1))","children":[{"type":"KEYWORD","word":"spaceddd","querypos":1}]},{"type":"AND","description":"AND(KEYWORD(team, querypos=2))","children":[{"type":"KEYWORD","word":"team","querypos":2}]}]}}}
            [transportInfo:protected] => Array
                (
                    [url] => http://127.0.0.1:9308/json/search
                    [headers] => Array
                        (
                            [0] => Content-Type: application/json
                        )

                    [body] => Array
                        (
                            [index] => movies
                            [profile] => 1
                            [query] => Array
                                (
                                    [bool] => Array
                                        (
                                            [must] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [match] => Array
                                                                (
                                                                    [*] => spaceddd team
                                                                )

                                                        )

                                                )

                                        )

                                )

                        )

                )

            [status:protected] => 200
            [response:protected] => Array
                (
                    [took] => 0
                    [timed_out] =>
                    [hits] => Array
                        (
                            [total] => 2
                            [hits] => Array
                                (
                                    [0] => Array
                                        (
                                            [_id] => 5
                                            [_score] => 1528
                                            [_source] => Array
                                                (
                                                    [year] => 1979
                                                    [rating] => 8.4
                                                    [title] => Alien
                                                    [plot] =>  After a space merchant vessel receives an unknown transmission as a distress call, one of the team's member is attacked by a mysterious life form and they soon realize that its life cycle has merely begun.
                                                )

                                        )

                                    [1] => Array
                                        (
                                            [_id] => 2
                                            [_score] => 1528
                                            [_source] => Array
                                                (
                                                    [year] => 2014
                                                    [rating] => 8.5
                                                    [title] => Interstellar
                                                    [plot] => A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.
                                                )

                                        )

                                )

                        )

                    [profile] => Array
                        (
                            [query] => Array
                                (
                                    [type] => OR
                                    [description] => OR( AND(KEYWORD(spaceddd, querypos=1)),  AND(KEYWORD(team, querypos=2)))
                                    [children] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => AND
                                                    [description] => AND(KEYWORD(spaceddd, querypos=1))
                                                    [children] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => KEYWORD
                                                                    [word] => spaceddd
                                                                    [querypos] => 1
                                                                )

                                                        )

                                                )

                                            [1] => Array
                                                (
                                                    [type] => AND
                                                    [description] => AND(KEYWORD(team, querypos=2))
                                                    [children] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => KEYWORD
                                                                    [word] => team
                                                                    [querypos] => 2
                                                                )

                                                        )

                                                )

                                        )

                                )

                        )

                )

            [params:protected] => Array
                (
                )

        )

    [array:protected] => Array
        (
            [0] => Array
                (
                    [_id] => 5
                    [_score] => 1528
                    [_source] => Array
                        (
                            [year] => 1979
                            [rating] => 8.4
                            [title] => Alien
                            [plot] =>  After a space merchant vessel receives an unknown transmission as a distress call, one of the team's member is attacked by a mysterious life form and they soon realize that its life cycle has merely begun.
                        )

                )

            [1] => Array
                (
                    [_id] => 2
                    [_score] => 1528
                    [_source] => Array
                        (
                            [year] => 2014
                            [rating] => 8.5
                            [title] => Interstellar
                            [plot] => A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.
                        )

                )

        )

    [total:protected] => 2
    [took:protected] => 0
    [timed_out:protected] =>
    [profile:protected] => Array
        (
            [query] => Array
                (
                    [type] => OR
                    [description] => OR( AND(KEYWORD(spaceddd, querypos=1)),  AND(KEYWORD(team, querypos=2)))
                    [children] => Array
                        (
                            [0] => Array
                                (
                                    [type] => AND
                                    [description] => AND(KEYWORD(spaceddd, querypos=1))
                                    [children] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => KEYWORD
                                                    [word] => spaceddd
                                                    [querypos] => 1
                                                )

                                        )

                                )

                            [1] => Array
                                (
                                    [type] => AND
                                    [description] => AND(KEYWORD(team, querypos=2))
                                    [children] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => KEYWORD
                                                    [word] => team
                                                    [querypos] => 2
                                                )

                                        )

                                )

                        )

                )

        )

    [facets:protected] =>
)
Document:5
year: 1979
rating: 8.4
title: Alien
plot:  After a space merchant vessel receives an unknown transmission as a distress call, one of the team's member is attacked by a mysterious life form and they soon realize that its life cycle has merely begun.
Document:2
year: 2014
rating: 8.5
title: Interstellar
plot: A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.

@Maxpl
Copy link
Author

Maxpl commented Dec 22, 2021

Sorry, its my bed constructor written by main README and 'match' added:

$client = new \Manticoresearch\Client($config);
$index = $client->index('main');
$results = $index->search('yellow green')
->match(['query' => 'yellow green', 'operator' => 'or'], 'title')
->get();

its work but not good results:)
I need match and set operator dynamically
without "->search" we have exception

looking at your code did that my correct code:

$client = new \Manticoresearch\Client($config);
$search = new \Manticoresearch\Search($client);
$results = $search->setIndex('main')
->match(['query' => 'yellow green', 'operator' => 'or'], 'title')
->get();

So I ended up losing the evening looking at the main project readme..
The search seems to work but does not work as I expect..
I would like new users not to follow my path

@sanikolaev
Copy link
Collaborator

->search('yellow green')
->match(['query' => 'yellow green', 'operator' => 'or'], 'title')

doesn't make sense to me. If we have it somewhere please let me know or make a PR to fix it in the readme. But I can't find it.

The search seems to work but does not work as I expect..

So what's wrong? Can you provide:

  • your full script
  • your current result
  • what you expect

@Maxpl
Copy link
Author

Maxpl commented Dec 23, 2021

ok i get you code:
php
require_once DIR . '/vendor/autoload.php';

use Manticoresearch\Client;
use Manticoresearch\Search;

$config = ['host'=>'127.0.0.1','port'=>9308];
$client = new \Manticoresearch\Client($config);
$index = $client->index('movies');

$params = [
'index' => 'movies',
['body' => ['silent'=>true ]]
];
$client->indices()->drop($params);

$index->create([
'title'=>['type'=>'text'],
'plot'=>['type'=>'text'],
'year'=>['type'=>'integer'],
'rating'=>['type'=>'float']
]);

$index->addDocuments([
['id'=>2,'title'=>'Interstellar','plot'=>'A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.','year'=>2014,'rating'=>8.5],
['id'=>3,'title'=>'Inception','plot'=>'A thief who steals corporate secrets through the use of dream-sharing technology is given the inverse task of planting an idea into the mind of a C.E.O.','year'=>2010,'rating'=>8.8],
['id'=>4,'title'=>'1917 ','plot'=>' As a regiment assembles to wage war deep in enemy territory, two soldiers are assigned to race against time and deliver a message that will stop 1,600 men from walking straight into a deadly trap.','year'=>2018,'rating'=>8.4],
['id'=>5,'title'=>'Alien','plot'=>' After a space merchant vessel receives an unknown transmission as a distress call, one of the team's member is attacked by a mysterious life form and they soon realize that its life cycle has merely begun.','year'=>1979,'rating'=>8.4]
]);

//$search = new Search($client);
//$search->setIndex('movies');
//$results = $search->profile()->match('spaceddd team')->get();
//
//!!!next code get from readme and add match metod in constructor
$results = $index->search('Interstellar Inception', 'title')
->match(['query' => 'Interstellar Inception', 'operator' => 'or'], 'title')
->profile()
->get();

print_r($results);

foreach($results as $doc) {
echo 'Document:'.$doc->getId()."\n";
foreach($doc->getData() as $field=>$value)
{
echo $field.": ".$value."\n";
}
}
➜ ~ php test.php
Manticoresearch\ResultSet Object
(
[position:protected] => 0
[response:protected] => Manticoresearch\Response Object
(
[time:protected] => 0.0027859210968018
[string:protected] => {"took":2,"timed_out":false,"hits":{"total":0,"hits":[]},"profile":{"query":{"type":"AND","description":"AND( AND( AND(KEYWORD(interstellar, querypos=1)), AND(KEYWORD(inception, querypos=2))), OR( AND(fields=(title), KEYWORD(interstellar, querypos=1)), AND(fields=(title), KEYWORD(inception, querypos=2))))","children":[{"type":"AND","description":"AND( AND(KEYWORD(interstellar, querypos=1)), AND(KEYWORD(inception, querypos=2)))","children":[{"type":"AND","description":"AND(KEYWORD(interstellar, querypos=1))","children":[{"type":"KEYWORD","word":"interstellar","querypos":1}]},{"type":"AND","description":"AND(KEYWORD(inception, querypos=2))","children":[{"type":"KEYWORD","word":"inception","querypos":2}]}]},{"type":"OR","description":"OR( AND(fields=(title), KEYWORD(interstellar, querypos=1)), AND(fields=(title), KEYWORD(inception, querypos=2)))","children":[{"type":"AND","description":"AND(fields=(title), KEYWORD(interstellar, querypos=1))","fields":["title"],"children":[{"type":"KEYWORD","word":"interstellar","querypos":1}]},{"type":"AND","description":"AND(fields=(title), KEYWORD(inception, querypos=2))","fields":["title"],"children":[{"type":"KEYWORD","word":"inception","querypos":2}]}]}]}}}
[transportInfo:protected] => Array.....

as you see results 0, but i hoped to see 2 result.
If this wrong path add main README you example with $search = new Search($client); with a mark "you must this with match metod".
If my use case of the constructor is allowed then this is a bug.

@sanikolaev
Copy link
Collaborator

//!!!next code get from readme and add match metod in constructor
$results = $index->search('Interstellar Inception', 'title')
->match(['query' => 'Interstellar Inception', 'operator' => 'or'], 'title')

Please point me to the place where it's said that you need to combine search() and match() in the same call. I can't find it.

as you see results 0, but i hoped to see 2 result.

You are trying to combine two different operators for some. You either use OR explicitly like:

$results = $index->search('Interstellar|Inception', 'title')
->profile()
->get();

or you match() which does OR by default.

Again, if the documentation in some place you need to do so please let me know where exactly it's written. We'll need to change that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants