Why can't I use my analyzer and get answer 'failed to find analyze'? - php

I made my index with analyzer like in documentation (there).
This is my index create:
$params = [
'index' => 'mytestindex',
'body' => [
'settings' => [
'analysis' => [
'index_analyzer' => [
'my_index_analyzer' => [
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => [
'lowercase',
'mynGram2'
],
],
],
'search_analyzer' => [
'my_search_analyzer' => [
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => [
'standard',
'lowercase',
'mynGram2'
],
],
],
'filter' => [
'mynGram2' => [
'type' => 'nGram',
'min_gram' => 2,
'max_gram' => 20,
],
],
],
'max_ngram_diff' => 50,
],
],
];
$x = $this->obj->indices()->create($params);
Then i try use my analyzer:
$params = [
'index' => 'mytestindex',
'body' => [
'analyzer' => 'my_search_analyzer',
'text' => 'текст проверить чтобы'
],
];
$x = $this->obj->indices()->analyze($params);
But I get this message:
'{"error":{"root_cause":[{"type":"remote_transport_exception","reason":"[PEREGOVOR2][127.0.0.1:9300][indices:admin/analyze[s]]"}],"type":"illegal_argument_exception","reason":"failed
to find analyzer [my_search_analyzer]"},"status":400}'
So... what am I doing wrong? Why can't I use my analyzer and get answer 'failed to find analyze'?

You're not building your analyzer correctly. You only need one analyzer section in your settings:
$params = [
'index' => 'mytestindex',
'body' => [
'settings' => [
'analysis' => [
'analyzer' => [ <--- change this
'my_index_analyzer' => [
'type' => 'custom',
"tokenizer" => "standard",
'filter' => [
"lowercase",
"mynGram2"
],
],
'my_search_analyzer' => [
"type" => "custom",
"tokenizer" => "standard",
'filter' => [
"standard",
"lowercase",
"mynGram2"
],
],
],
'filter' => [
'mynGram2' => [
"type" => "nGram",
"min_gram" => 2,
"max_gram" => 20,
],
],
],
"max_ngram_diff" => "50",
],
],
];
$x = $this->obj->indices()->create($params);

Related

Getting unknown property: Da\User\Module::isGuest yii2-usuario

I'm install 2amigos/yii2-usuario:~1.5.1 on a yii2-basic-template, using https://yii2-usuario.readthedocs.io/en/latest/. However, it returns this error (Getting unknown property: Da\User\Module::isGuest yii2-usuario) in any view.
My config/console.php:
'components' => [
...
'authManager' => [
'class'=> 'yii\rbac\DbManager',
],
...
],
'controllerMap' => [
'migrate' => [
'class' => \yii\console\controllers\MigrateController::class,
'migrationPath' => [
'#app/migrations',
'#yii/rbac/migrations', // Just in case you forgot to run it on console (see next note)
],
'migrationNamespaces' => [
'Da\User\Migration',
],
],
],
My config/web.php:
'components' => [
...
'user' => [
'class' => Da\User\Module::class,
'classMap' => [
'User' => app\models\User::class,
],
],
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
'view' => [
'theme' => [
'pathMap' => [
'#Da/User/resources/views' => '#app/views/user'
]
]
]
],
I managed to solve it with help.
Follow the line:
Remove : config/web.php
'user' => [
'identityClass' => 'app\models\Users',
'enableAutoLogin' => true,
'enableSession' => true,
],
'user-management' => [
'class' => 'webvimark\modules\UserManagement\UserManagementModule',
'on beforeAction'=>function(yii\base\ActionEvent $event) {
if ( $event->action->uniqueId == 'user-management/auth/login' ){
$event->action->controller->layout = 'loginLayout.php';
};
},
],
add into config/web.php:
'components' =>[ ...
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
'view' => ['theme' => [ 'pathMap' => ['#Da/User/resources/views' => '#app/views/user']]] //If your view is modified.
]
'modules' => ['user' => [
'class' => \Da\User\Module::class,
'allowAccountDelete' => true,
'enableRegistration' => false,
'administratorPermissionName' => 'user-management']
...]
``

How to use MDword to generate multi-level nested Office Word?

effect picture:
https://i.stack.imgur.com/f2r3O.png
github address:
https://github.com/mkdreams/MDword
data:
$arr = [
[
"title1" => "title1",
"meeting_content"=>[
[
"title11" => "title11,title11",
"content11" => "content,content,content,content,content,content,content,content,content,"
],
[
"title22" => "title22,title22",
"content22" => "content,content,content,content,content,content,content,content,content,"
],
],
"children" => []
],
[
"title" => "title",
"meeting_content"=>[
],
"children"=>[
[
"title1" => "title1",
"meeting_content"=>[
[
"title11" => "title11,title11",
"content11" => "content,content,content,content,content,content,content,content,content,"
],
[
"title22" => "title22,title22",
"content22" => "content,content,content,content,content,content,content,content,content,"
],
],
],
[
"title2" => "title2",
"meeting_content"=>[
[
"title11" => "title11,title11",
"content11" => "content,content,content,content,content,content,content,content,content,"
],
[
"title22" => "title22,title22",
"content22" => "content,content,content,content,content,content,content,content,content,"
],
],
],
],
],
];
How to use MDword to generate multi-level nested Office Word?
Now I need to, using a MDword extension of PHP, write this multidimensional data into a Word document, I don't know what to do, it has the effect picture, and Github address, thank you
You can use pstyle.You can see the demo.
Details as follows(You must update to the latest version):
data
$numDatas = [
[
'title'=>'title-1',
'content'=>'content-1'
],
[
'title'=>'title-2',
'sub'=>[
[
'title'=>'subTitle-2-1',
'content'=>'content-2-1',
],
[
'title'=>'subTitle-2-2',
'content'=>'content-2-2',
],
]
],
[
'title'=>'title-3',
'sub'=>[
[
'title'=>'subTitle-3-1',
'content'=>'content-3-1',
],
[
'title'=>'subTitle-3-2',
'content'=>'content-3-2',
],
]
],
];
temple IMG:
https://i.stack.imgur.com/dS1U1.png
code
$TemplateProcessor->cloneP('num',count($numDatas));
foreach($numDatas as $idx => $numData) {
$TemplateProcessor->cloneP('num'.'#'.$idx,3);
$TemplateProcessor->setValue('num'.'#'.$idx.'#0',[['text' => $numData['title'], 'pstyle' => 'numstyle-level-1', 'type' => MDWORD_TEXT]]);
if(isset($numData['content'])) {
$TemplateProcessor->setValue('num'.'#'.$idx.'#1',[['text' => $numData['content'], 'pstyle' => 'numstyle-level-3', 'type' => MDWORD_TEXT]]);
}else{
$TemplateProcessor->deleteP('num'.'#'.$idx.'#1');
}
$subName = 'num'.'#'.$idx.'#2';
if(isset($numData['sub'])) {
$TemplateProcessor->cloneP($subName,count($numData['sub']));
foreach($numData['sub'] as $subIdx => $subData) {
$TemplateProcessor->cloneP($subName.'#'.$subIdx,2);
$TemplateProcessor->setValue($subName.'#'.$subIdx.'#0',[['text' => $subData['title'], 'pstyle' => 'numstyle-level-2', 'type' => MDWORD_TEXT]]);
$TemplateProcessor->setValue($subName.'#'.$subIdx.'#1',[['text' => $subData['content'], 'pstyle' => 'numstyle-level-3', 'type' => MDWORD_TEXT]]);
}
}else{
$TemplateProcessor->deleteP($subName);
}
}
$TemplateProcessor->deleteP('numstyle');
result IMG:
https://i.stack.imgur.com/sb0MB.png

Elasticsearch search results filtering

I am new to Elasticsearch and I am using REST API for PHP to play around with data returned. I am using following code to retrieve data.
$params = [
'index' => 'my_search',
'type' => 'mytype',
'from' => 0,
'size' => 10,
'body' => [
'query' => [
'bool' => [
'must' => [
[ 'match' => [ 'validated' => true ] ],
[ 'match' => [ 'image' => true ] ]
]
]
],
'sort' => [
'created_at' => [ 'order' => 'asc']
]
]
];
Above code returns data perfectly matching "validated=>true" and "image=>true".
Further I want to add open text search like we use /_search/?q=Apple macbook. I have tried to use match, multi_match, query_string options, but couldn't get success.
So, I want to retrieve results from ES that have "validated=>true", "image=>true" and matches with text "Apple macbook".
Thanks in advance.
You can try with query_string or simple_query_string
$params = [
'index' => 'my_search',
'type' => 'mytype',
'from' => 0,
'size' => 10,
'body' => [
'query' => [
'bool' => [
'must' => [
[ 'match' => [ 'validated' => true ] ],
[ 'match' => [ 'image' => true ] ],
[ 'query_string' => [ 'query' => 'Apple macbook' ] ]
]
]
],
'sort' => [
'created_at' => [ 'order' => 'asc']
]
]
];
$params = [
'index' => 'my_search',
'type' => 'mytype',
'from' => 0,
'size' => 10,
'body' => [
'query' => [
'bool' => [
'must' => [
[ 'match' => [ 'validated' => true ] ],
[ 'match' => [ 'image' => true ] ],
[ 'simple_query_string' => [ 'query' => 'Apple macbook' ] ]
]
]
],
'sort' => [
'created_at' => [ 'order' => 'asc']
]
]
];
you can also do this by
enabling all_field mapping for your index, you can do that by following the below URL
https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-all-field.html
and then use the below ES query:
$params = [
'index' => 'my_search',
'type' => 'mytype',
'from' => 0,
'size' => 10,
'body' => [
'query' => [
'bool' => [
'must' => [
[ 'match' => [ '_all' => 'Apple macbook' ] ],
[ 'match' => [ 'validated' => true ] ],
[ 'match' => [ 'image' => true ] ]
]
]
],
'sort' => [
'created_at' => [ 'order' => 'asc']
]
]
];

How to optimize elastic search query

I have been reading through elastic search docs over the last few months and have continued to optimize my query, but I can't seem to get a search query below 500-600ms. Locally with less data I can get responses in ~80-200ms.
To outline what I am trying to accomplish:
I have 12 different models in Laravel that are searchable from a single search bar. As someone types it is searched and returned in a list of results.
Currently, I have this for my search query. Are there any references for how I can improve this? I looked into multi_match, but I was having issues with partial matches and specifying all fields.
$results = $this->elastic->search([
'index' => config('scout.elasticsearch.index'),
'type' => $type ?? implode(',', array_keys($this->permissions, true, true)),
'body' => [
'query' => [
'bool' => [
'must' => [
[
'query_string' => [
'query' => "$searchQuery*",
],
],
],
'filter' => [
[
'term' => [
'account_id' => $accountId,
],
],
],
'should' => [
[
'term' => [
'_type' => [
'value' => 'customers',
'boost' => 1.3,
],
],
],
[
'term' => [
'_type' => [
'value' => 'contacts',
'boost' => 1.3,
],
],
],
[
'term' => [
'_type' => [
'value' => 'users',
'boost' => 1.3,
],
],
],
[
'term' => [
'_type' => [
'value' => 'chart_accounts',
'boost' => 1.2,
],
],
],
],
],
],
'from' => $from,
'size' => $size,
],
]);

Elasticsearch php giving error when setting 2 criterias in must clause

I am trying to add multiple criterion to ElasticSearch PHP in must clause, but it is giving me a 500 Error.
My params are:
$params = ['index' => 'smartjn',
'type' => 'feed_details',
'size' => 10,
'body' => [
'sort' => [
'sorter' => [
'order' => 'desc',
'mode' => 'max'
]
],
'query' => ['bool' => [
'must' => [
['match' => ['approvalStatus' => 'approved']],
[ '_id' => [
'$lt' => new MongoDB\BSON\ObjectId($documentid)
]
]
],
'must_not' => ['term' => ['muteFeedUserIds' => $userID]],
'must_not' => ['term' => ['muteUserIds' => $userID]]
]
]
]
];
Please note that this works if I remove the second criteria in must clause i.e.
$params = ['index' => 'smartjn',
'type' => 'feed_details',
'size' => 10,
'body' => [
'sort' => [
'sorter' => [
'order' => 'desc',
'mode' => 'max'
]
],
'query' => ['bool' => [
'must' => [
['match' => ['approvalStatus' => 'approved']]
],
'must_not' => ['term' => ['muteFeedUserIds' => $userID]],
'must_not' => ['term' => ['muteUserIds' => $userID]]
]
]
]
];
Any idea what am I missing?
Thanks
check this out.
'query' => ['bool' => [
'must' => [
['match' => ['approvalStatus' => 'approved']],
[ 'ids' => [
'values' => [new MongoDB\BSON\ObjectId($documentid)]
]
]
],
'must_not' => ['term' => ['muteFeedUserIds' => $userID]],
'must_not' => ['term' => ['muteUserIds' => $userID]]
]
If that doesnt work i am giving you the raw as i am not good with elasticphp
{
"query": {
"bool": {
"must": [
{
"ids": {
"type": "type_of_index"
"values": ["AVbqtjXfoKQ0pubF_-NA"]
}
}
]
}
}
}
type is optional
Just add this ids part under must area.

Categories