thorsten / phpMyFAQ

phpMyFAQ - Open Source FAQ web application for PHP 8.1+ and MySQL, PostgreSQL and other databases
https://www.phpmyfaq.de
Mozilla Public License 2.0
588 stars 253 forks source link

Elastic search - how to test #1890

Closed ushah001 closed 3 years ago

ushah001 commented 3 years ago

Describe the bug I have created index in elastic search configuration page. When I search with less than 4 characters, it returns data. For letters more than 4 character, I am getting error.

To Reproduce Steps to reproduce the behavior:

  1. Go to elastic search configuration on Admin side and click Create Index,
  2. Go to Search page on front-end
  3. Search for string less than and greater than 4 characters
  4. Enable debug mode and see error

Expected behavior Search should happen without errors.

Screenshots image

phpMyFAQ (please complete the following information):

Additional context I am not sure how to know if my search is working through elastic search or full-text.

thorsten commented 3 years ago

What happens if you disable the debug mode?

thorsten commented 3 years ago

What language do you use?

ushah001 commented 3 years ago

en only.

ushah001 commented 3 years ago

nothing happens. only white screen appears.

thorsten commented 3 years ago

Looks like nothing's returned for more than 4 letters.

thorsten commented 3 years ago

hm, what happens if you use the "find as you type" feature? Does it work?

thorsten commented 3 years ago

And please upgrade to phpMyFAQ 3.0.7

ushah001 commented 3 years ago

If I disable elastic search from Edit Configuration --> Search then "find as you type" feature works and search works as well. But I need to make it work with Elastic Search.

image image

And in my organization, we needed few custom checkboxes and that's why we are not upgrading to 3.0.7 as we have to code again after the upgrade.

thorsten commented 3 years ago

Some errors you got are fixed with 3.0.7. What kind of custom checkboxes do you need? Are they interesting for all users?

ushah001 commented 3 years ago

custom code changes like - 1) new checkbox added for Peer review as my organization needed peer review and then publishing , same way for legal review 2) change in admin side report - added which user did published the FAQs, if FAQ is still active or no etc.

I will try to update on my local and see.

I have one question. Although I am very much new to elastic search. If I create index using phpmyfaq platform only, do I need to do any other code change/config change to index my data so that It starts searching using elastic search ?

What I am unable to understand is, even after index is created - how data in my knowledge base and elastic search is connected.

Sorry for my very basic questions.

ushah001 commented 3 years ago

After upgrading to 3.0.7, it is still showing blank page when I search:

image

image

image

image

thorsten commented 3 years ago

You have to run a "full import" on the Elasticsearch page. Otherwise nothing is in the search index.

thorsten commented 3 years ago

@ushah001 The two feature mentioned are feature that I could integrate into 3.1 for all users, they sound useful.

ushah001 commented 3 years ago

@thorsten , thanks for including these features to phpmyfaq.

Further, When I do full import, I get response like below. image

Now, when I search, I have below issues:

1) auto-complete only works for more than 4 characters search. [this was not the case with full-text search.]

image

2) when I search for a word less than 4 characters, even though it is part of FAQ question, it gives below error in debug mode - ON. When debug mode is - OFF , it yields no response (blank page).

ie. I wanted to search for - Review. I types revi and hit search.

Debug - True image

Debug - False image

When I search for a whole word, ie. Review , it brings the result.

image

Is this nature of implemented elastic search ?

elastic search is mapped to phpmyfaq correctly, I can see below in kibana after I did full import and searched for more than 4 characters words. image

thorsten commented 3 years ago

I think you missed one fix for the autocomplete stuff, did you change all JS files during the last updates? The wrong behaviour for the auto-completion was fixed in one of the 3.0.x releases and it was in a JS file. I'll check the PHP error when you turned on the debug mode.

ushah001 commented 3 years ago

@thorsten , it looks like any word which is not part of the FAQ is giving me the error. not just less than 4 character. I debugged the code and found that issue is with Elasticsearch.php --> search function.

when matching FAQs are not found, it should have returned No FAQs found.

Could you please confirm this.

image

thorsten commented 3 years ago

Well, on my test systems it returns "no FAQs found", I cannot reproduce the error you got. Is it possible to get your database dump?

ushah001 commented 3 years ago

sure anyway it is my localhost test db only. where should i attach it ? it is .sql file.

thorsten commented 3 years ago

You can send it to thorsten AT phpmyfaq DOT de

ushah001 commented 3 years ago

hey @thorsten , finally I figured out the problem.

when there is no matching result, the output from Elasticsearch.php --> search function --> $result = $this->client->search($searchParams); [line no 101] is as below:

image

when there is a match, the output is as below: image

Now, the line of code: $result['hits']['total'] is never empty when there is no match.

I changed the line to $result['hits']['hits'] and it gives me correct output.

image

image

image

all this happens, when elastic search support is enabled.

image

thorsten commented 3 years ago

Ha, and I know, why I couldn't reproduce it, as I fixed it by accident:

https://github.com/thorsten/phpMyFAQ/blob/main/phpmyfaq/src/phpMyFAQ/Search/Elasticsearch.php#L106

ushah001 commented 3 years ago

Great. one last question before I close this, it is regarding full import.

Just to clarify, do I need to do full-import every time as questions are updated or added every day on my side. So do I have to do full-import only once for the very first time after index is created in elastic search or regularly I have to do full-import ?

thorsten commented 3 years ago

The full import is only needed for the first time or e.g. if you want to clean the Elasticsearch index. If you add or update FAQs and you enabled the Elasticsearch feature, new or updated FAQs will be also added to Elasticsearch.