php-cuong / magento2-faqs-extensions

Magento 2 FAQ Extension Free
83 stars 56 forks source link

Search crashes: Invalid method PHPCuong\Faq\Block\Search\Search::filterProvider #22

Open dazz397 opened 6 years ago

dazz397 commented 6 years ago

If you search for something that matches a value the search will crash /faq/search/?s=feet

If you search for something with no matches it returns fine /faq/search/?s=xxxxx

I was able to replicate this on 2.1.7 and 2.1.7.1

SherifElfadaly commented 6 years ago

I have created a pull request to fix this issue. Check #23

ghost commented 6 years ago

@SherifElfadaly great patch! I can confirm the patch is working and to me it should be merged to master as soon as possibile since at the current state the search functionality is broken.

lamaithanh commented 6 years ago

@SherifElfadaly fixed a part of the search results. I searched with more than 3 words which were copied from one of the answers. But results listed all questions in my English Store (some times it also included all questions from my other Chinese Store)

dazz397 commented 2 years ago

@lamaithanh I know this is years later but the query is not built correctly when there are multiple keywords. You can correct this by adding parenthesis to the query at line 175 like this:

    for ($i=0; $i<count($explode); $i++) {
        if ($i == 0) {
            $select->where('(faq.title LIKE ?', "%{$explode[$i]}%");
        } else {
            $select->orWhere('faq.title LIKE ?', "%{$explode[$i]}%");
        }
        if ($i == count($explode)-1) {
            $select->orWhere('faq.content LIKE ?)', "%{$explode[$i]}%");
        } else {
            $select->orWhere('faq.content LIKE ?', "%{$explode[$i]}%");
        }
    }