ganuonglachanh / flarum-sonic

Support search in flarum by sonic
GNU Affero General Public License v3.0
19 stars 6 forks source link

执行 addtoindex 命令报错 InvalidArgumentException #7

Open cnych opened 2 years ago

cnych commented 2 years ago

php flarum sonic:addtoindex Starting... Flush old postCollection: 1 Adding to index...

In Ingest.php line 63:

[InvalidArgumentException]

sonic:addtoindex

sonic 1.3.2 版本,flarum 1.2.0 版本

ganuonglachanh commented 2 years ago

Did you do the step 3 Change info in admin setting before run this command?

cnych commented 2 years ago

@ganuonglachanh 配置了的

image

因为我这里是跑在k8s里面的,所以需要修改下host地址

ganuonglachanh commented 2 years ago

If you're sure the host is correct, does the password is same as the default (SecretPassword)?

P/S: and if you're using Chinese, locale should not be "eng" (an ISO 639-3 locale code eg. eng for English)

If alls above info is correct, please send you detail setup info :)

cnych commented 2 years ago

@ganuonglachanh 中文的话 locale code 应该设置成多少?zho?不对,用默认的 eng 在 Sonic 这边是可以生成一部分索引的,只是不全~

Ingest.php 这个文件是在什么地方呢?没有找到

ganuonglachanh commented 2 years ago

Sonic locale code for Chinese should be "cmn"

https://github.com/ppshobi/psonic/blob/master/src/Ingest.php

Please send you detail setup info for futher investigation and could you please use English for conversation?

cnych commented 2 years ago

Sorry!

3Q

ganuonglachanh commented 2 years ago

Thanks, I tested with valeriansaliou/sonic:v1.3.2 with no error.

Is your flarum install is test data? Could you send me the exported database of test flarum?

If you couldn't provide database, what is your charset and collation setting in flarum config.php ?

You can try to debug the content that have error by adding this code to the line 69 of src/Console/AddToIndex.php

echo $post->content . PHP_EOL;

then rerun the php flarum sonic:addtoindex command

lihaorr commented 2 years ago

image

Hello, I encountered the same problem, I did the debugging according to your meaning, and the content of one of my articles appeared above the console error. Also I have set the “cmn”

thx!

tansongchen commented 2 years ago

Same problem here. I couldn't provide the database but I can share the config in config.php:

    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',

When I add the echo $post->content . PHP_EOL; to the code, I noticed that before Ingest.php throws InvalidArgumentException, a very long post is printed in the console and it stayed there for quite a while. I guess it is something related to size limit exceeded...

n0099 commented 1 year ago

a very long post is printed in the console and it stayed there for quite a while

After update codes near https://github.com/ganuonglachanh/flarum-sonic/blob/ebbeb19331055f7491157018ea4b5c7a09fc373d/src/Console/AddToIndex.php#L71 to: image we can see that for a 52kib long string it takes 60s long hanging to throw the exception: image

So I guess there might be some hard timeout limit being set to 60s

I guess it is something related to size limit exceeded...

This issue from dependency might be related: https://github.com/ppshobi/psonic/pull/23 After applying this pr manually, I'm still encountering this exception.

n0099 commented 1 year ago

A temp workaround is to continue push after the exception thrown after 60s timeout, for this u can update this line https://github.com/ganuonglachanh/flarum-sonic/blob/ebbeb19331055f7491157018ea4b5c7a09fc373d/src/Console/AddToIndex.php#L71 with

                try {
                    $ingest->push('postCollection', 'flarumBucket', $post->id,$post->content, $locale);
                } catch (\Throwable $th) {
                    echo "$post->id failed: " . strlen($post->content) . ' bytes ' . round((microtime(true) - $start) * 1000, 2) . 'ms passed' . PHP_EOL;
                }
n0099 commented 1 year ago

I found a note from the author of upstream sonic repo: https://github.com/valeriansaliou/sonic/issues/43#issuecomment-476492283

Notice that there's no ERR for the async protocol (ie. if an EVENT never comes due to an error). You may thus implement a timeout strategy on your end.

ganuonglachanh commented 1 year ago

Thanks @n0099 for the investigation, fixed in new release

tansongchen commented 1 year ago

Hi @ganuonglachanh , I'm willing to tryout the new fix, but it seems that the new release is not installable by composer? Running composer update still gives 0.1.5

n0099 commented 1 year ago

Seems he forgot to sync the release on packagist. You can manually change the composer package source to the github repo: https://stackoverflow.com/questions/12954051/use-php-composer-to-clone-git-repo https://getcomposer.org/doc/05-repositories.md, or just git clone and rename its path inside vendor.

tansongchen commented 1 year ago

Seems he forgot to sync the release on packagist.

You can manually change the composer package source to the github repo: https://stackoverflow.com/questions/12954051/use-php-composer-to-clone-git-repo https://getcomposer.org/doc/05-repositories.md, or just git clone and rename its path inside vendor.

Good suggestion, will try 😋

ganuonglachanh commented 1 year ago

Released new version, I lost in time @@