0

I use php to send and receive data from mysql database my query is

SELECT 
 *
FROM (

  SELECT 
   *
  FROM
   test
  WHERE
   MATCH(word) AGAINST('+hello ')      
) AS fulltext_scan
WHERE 
 fulltext_scan.word REGEXP '^hello '

when I search for english word its working well but when I search for swedish(ä,ö,å) word I got this error

Got error 'nothing to repeat at offset 1' from regexp

I have array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'") in my connection and header('Content-Type: text/html; charset=utf-8');

when I test the query directly from phpmyadmin its working well even with swedish words

I want to use AS for sorting like

SELECT  pages.*, MATCH (head, body) AGAINST ('some words') AS
      AND  column REGEXP '^hello ' relevance,
        MATCH (head) AGAINST ('some words') AS title_relevance
    FROM  pages
    WHERE  MATCH (head, body) AGAINST ('some words')
    ORDER BY  title_relevance DESC, relevance DESC

to get {hello} first

how can I fix that in my php page?

Rick James
  • 135,179
  • 13
  • 127
  • 222
cordn
  • 1
  • 3

1 Answers1

0

What is the goal? To see if word starts with ögon? That task can very efficiently be done with

WHERE word LIKE 'ögon %';

together with INDEX(word), assuming it is a VARCHAR, not a TEXT.

Please provide SHOW CREATE TABLE test. There could be issues with the CHARACTER SET.

What do you get with SELECT HEX(word) ...? If you are properly using utf8/utf8mb4, it should show C3B6 67 6F 6E (without spacing).

Unless you are using MySQL 8.0, do not expect REGEXP to properly understand accented letters.

There is possibly no need for the extra SELECT; simply do

SELECT ...
    WHERE MATCH(word) AGAINST(...)
      AND word LIKE ...

The MATCH will happen first, then the LIKE will check the few rows that MATCHed.

Rick James
  • 135,179
  • 13
  • 127
  • 222
  • thank you but I want to use ```AS``` for sorting like ```SELECT pages.*, MATCH (head, body) AGAINST ('some words') AS AND column REGEXP '^hello ' relevance, MATCH (head) AGAINST ('some words') AS title_relevance FROM pages WHERE MATCH (head, body) AGAINST ('some words') ORDER BY title_relevance DESC, relevance DESC``` to get {hello} first – cordn Jun 28 '19 at 00:04
  • `AS AND` does not compute. What is that a typo for? – Rick James Jun 28 '19 at 02:48