dave1950 Posted May 16, 2014 Share Posted May 16, 2014 I have a MySql database (Server Version 5.6.12) with a fulltext index on the SectionText field in the FD table with this structure: CREATE TABLE `FD` ( `FTS_DOC_ID` bigint(20) unsigned NOT NULL, `ReadingNo` int(11) DEFAULT NULL, `SequenceNo` int(11) DEFAULT NULL, `SectionTypeID` int(11) DEFAULT NULL, `SectionText` longtext, `FullDocNo` varchar(11) CHARACTER SET utf8 NOT NULL, `DocType` varchar(11) CHARACTER SET utf8 DEFAULT NULL, UNIQUE KEY `FTS_DOC_ID_INDEX` (`FTS_DOC_ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; I am able to do a very accurate fulltext proximity search (92 documents found) in PHPMyAdmin using this syntax: SELECT SectionText FROM fd WHERE DocType = "text" AND MATCH (SectionText) AGAINST ('"liver hepatic" @3' IN BOOLEAN MODE) ORDER BY FTS_DOC_ID But when I try to use this query on a webpage I get this error message: Parse error: syntax error, unexpected 'liver' (T_STRING) in C:\wamp\www\ecr\proximity.php on line 77 When I remove the quotes like this: MATCH (SectionText) AGAINST ('liver hepatic @3' IN BOOLEAN MODE) There is no error, but there are no documents found. Realistically, to do searches on the web, I need to use search variables provided via an input form (and preferably a parameterized query) such as: MATCH (SectionText) AGAINST (':search1 :search2 @:proximity' IN BOOLEAN MODE) But this also returns no documents found. I need help getting this implemented on a web page. If this needs to be posted in another forum (PHP), please advise. But since the proximity search feature seems to be relatively new and somewhat obscure (couldn’t find anything about implementing it on a webpage via Google), I thought it best to start here. Any help in solving this is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/288537-parameterized-fulltext-proximity-search/ Share on other sites More sharing options...
Solution Barand Posted May 16, 2014 Solution Share Posted May 16, 2014 Try escaping the quotes $sql = "SELECT SectionText FROM fd WHERE DocType = "text" AND MATCH (SectionText) AGAINST ('\"liver hepatic\" @3' IN BOOLEAN MODE) ORDER BY FTS_DOC_ID"; Quote Link to comment https://forums.phpfreaks.com/topic/288537-parameterized-fulltext-proximity-search/#findComment-1479711 Share on other sites More sharing options...
dave1950 Posted May 16, 2014 Author Share Posted May 16, 2014 Yes, that solved it. Thanks so much. Quote Link to comment https://forums.phpfreaks.com/topic/288537-parameterized-fulltext-proximity-search/#findComment-1479723 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.