Editing
MySQL full text search equivalents to Google search
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Instruction of SQL syntax ==== (1) [https://www.w3resource.com/mysql/string-functions/mysql-position-function.php MySQL POSITION() function - w3resource] "MySQL POSITION() returns the position of a substring within a string." <pre> SET @term := "吸星大法"; SET @message := "笑傲江湖中嵩山派掌門左冷禪所創掌法,可發出至陰至寒的真氣。左冷禪與任我行比武時,以此功對付吸星大法,使其全身凍僵、天池穴被封;與岳不群比劍奪帥時,左又使出寒冰神掌,與紫霞神功旗鼓相當、不分勝敗。 原文網址:https://kknews.cc/zh-tw/culture/xzaxbq.html"; SELECT POSITION(@term IN @message) -- > returns 46 </pre> (2) Avoid the the start position is 0 or negative. Minimum start position of each paragraph is 1. <pre> SELECT IF( POSITION(@term IN @message) > 0 && POSITION(@term IN @message) -10 < 0 , 1 , POSITION(@term IN @message) -10) -- > returns 36 = 46 - 10 </pre> (3) Show 10 characters before or after the search keywords. [https://www.w3resource.com/mysql/string-functions/mysql-substring-function.php MySQL SUBSTRING() function - w3resource]"returns a specified number of characters from a particular position of a given string." <pre> SELECT @message , CASE WHEN POSITION(@term IN @message) > 0 THEN SUBSTRING(@message , IF( POSITION(@term IN @message) > 0 && POSITION(@term IN @message) -10 < 0 , 1 , POSITION(@term IN @message) -10) , CHAR_LENGTH(@term) + 20 ) ELSE '' END AS `scrapbook`; -- > returns 行比武時,以此功對付吸星大法,使其全身凍僵、天池 </pre> <pre> SET @term := "吸星大法"; SET @message := "原文網址:https://kknews.cc/zh-tw/culture/xzaxbq.html"; SELECT @message , CASE WHEN POSITION(@term IN @message) > 0 THEN SUBSTRING(@message , IF( POSITION(@term IN @message) > 0 && POSITION(@term IN @message) -10 < 0 , 1 , POSITION(@term IN @message) -10) , CHAR_LENGTH(@term) + 20 ) ELSE '' END AS `scrapbook` -- Returned result of scrapbook column: Show 10 characters before or after the search keywords. -- [EMPTY] </pre>
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information