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

Search for exact phrases not working #1340

Open
nighknight opened this issue Aug 1, 2017 · 6 comments
Open

Search for exact phrases not working #1340

nighknight opened this issue Aug 1, 2017 · 6 comments
Assignees

Comments

@nighknight
Copy link
Contributor

Hello!
The search for exact phrases using quotes ("exact phrase") is not working in the current version (2.9.9). The search strings seems to be converted to 'exact AND phrase'.

See screenshot:
grafik

The first result should not be found as it does not contain the exact search string "die Suche nicht", but only the string "die Suche mit Anführungszeichen nicht".

I did some research and this issue seems to be related to the escaping, see
https://stackoverflow.com/questions/16674139/php-mysql-boolean-full-text-searches-exact-string-operator-gives-differ

Unfortunately, my knowledge of PHP / MySQL is rather limited, so I am unable to fix the problem myself, but maybe this is helpful for you!

@thorsten
Copy link
Owner

thorsten commented Aug 1, 2017

How many entries do you have? I think the search switches back to a "LIKE" search.

@thorsten thorsten self-assigned this Aug 1, 2017
@thorsten thorsten added this to the 2.9.10 milestone Aug 1, 2017
@nighknight
Copy link
Contributor Author

I got three systems running:

  • one production system (~500 entries running 2.8.29)
  • one test system, where I am currently testing an update to 2.9.x (same ~500 entries)
  • one basic development system (3 entries, used to make the screenshots)

The issue is present on all three systems.

If I echo the resulting SQL query and paste it to phpMyAdmin, the result is ok.

Screenshot from development/phpmyfaq/inc/PMF/DB/Mysqli.php
grafik

Resulting query

SELECT fd.id AS id, fd.lang AS lang, fd.solution_id AS solution_id, faqcategoryrelations.category_id AS category_id, fd.thema AS question, fd.content AS answer FROM faqdata AS fd LEFT JOIN faqcategoryrelations ON fd.id = faqcategoryrelations.record_id AND fd.lang = faqcategoryrelations.record_lang WHERE MATCH (fd.thema, fd.content, fd.keywords) AGAINST ('"suche nicht"' IN BOOLEAN MODE) AND fd.lang = 'de' AND fd.active = 'yes' 

phpMyAdmin Output
grafik

@nighknight
Copy link
Contributor Author

Further comment: I just realized that the relation between the search words is actually a logical "OR" and not an "AND". So "suche irgendwas" actually results in the same output.

@thorsten
Copy link
Owner

thorsten commented Aug 1, 2017

This is the search code for MySQL:

https://github.com/thorsten/phpMyFAQ/blob/2.9/phpmyfaq/inc/PMF/Search/Database/Mysqli.php#L86-L125

If the first query does not return anything, a LIKE search will be executed.

@nighknight
Copy link
Contributor Author

Thanks for the clarification, I was not aware of that.

However, in my case two results are found and returned immediately. No LIKE search is executed, see output:

SELECT fd.id AS id, fd.lang AS lang, fd.thema AS thema, fcr.category_id AS category_id, fv.visits AS visits FROM faqdata fd LEFT JOIN faqcategoryrelations fcr ON fd.id = fcr.record_id AND fd.lang = fcr.record_lang LEFT JOIN faqvisits fv ON fd.id = fv.id AND fv.lang = fd.lang LEFT JOIN faqdata_group fdg ON fd.id = fdg.record_id LEFT JOIN faqdata_user fdu ON fd.id = fdu.record_id WHERE fd.date_start <= '20170802133021' AND fd.date_end >= '20170802133021' AND fd.active = 'yes' AND fcr.category_id = 0 AND fd.lang = 'de' GROUP BY fd.id, fd.lang, fd.thema, fcr.category_id, fv.visits ORDER BY id DESC
SELECT fd.id AS id, fd.lang AS lang, fd.solution_id AS solution_id, faqcategoryrelations.category_id AS category_id, fd.thema AS question, fd.content AS answer FROM faqdata AS fd LEFT JOIN faqcategoryrelations ON fd.id = faqcategoryrelations.record_id AND fd.lang = faqcategoryrelations.record_lang WHERE MATCH (fd.thema, fd.content, fd.keywords) AGAINST ('"suche nicht"' IN BOOLEAN MODE) AND fd.lang = 'de' AND fd.active = 'yes'
Number of results: 2
SELECT user_id AS permission FROM faqdata_user WHERE record_id = 2
SELECT user_id AS permission FROM faqdata_user WHERE record_id = 3
SELECT MAX(id) AS current_id FROM faqsearches
INSERT INTO faqsearches (id, lang, searchterm, searchdate) VALUES (62, 'de', '"suche nicht"', '2017-08-02 13:30:21')

So my problem is not connected to the LIKE search.

@thorsten thorsten removed this from the 2.9.10 milestone Feb 17, 2018
@nighknight
Copy link
Contributor Author

I did some more analysis of this issue by turning on the mysql query log.

It revealed a problem with the encoding of the quotes:

SELECT
	fd.id AS id, fd.lang AS lang, fd.solution_id AS solution_id, 
	faqcategoryrelations.category_id AS category_id, 
	fd.thema AS question, fd.content AS answer
FROM
	faqdata AS fd  
		LEFT JOIN faqcategoryrelations ON  fd.id = faqcategoryrelations.record_id 
		AND fd.lang = faqcategoryrelations.record_lang
WHERE
	MATCH (fd.thema, fd.content, fd.keywords) 
		AGAINST ('&#39;die suche nicht&#39;' IN BOOLEAN MODE)
			AND fd.lang = 'de' AND fd.active = 'yes'

So basically the quotes in the query are not shown as quotes but as html entities (&#39;).

As a test, I put a htmlspecialchars_decode() before the final call to mysql and then the query was executed correctly.

Screenshot from development/phpmyfaq/inc/PMF/DB/Mysqli.php
grafik

Resulting output
grafik

Maybe this helps?
It strongly assume that my hack does not constitute a proper fix...

Note: During the research, I found a comment that the encoding in htmlspecialchars($str, $quoteStyle, "UTF-8") is case sensitive:

grafik
Source

In development/phpmyfaq/inc/PMF/String.php it is actually lower case, but should be upper case according to the comment:
grafik

@stale stale bot added the wontfix label Jan 1, 2023
@thorsten thorsten removed the wontfix label Jan 1, 2023
Repository owner deleted a comment from stale bot Sep 22, 2023
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