MySQL full text search equivalents to Google search: Difference between revisions
| Line 35: | Line 35: | ||
* Searched the keywords e.g. {{kbd | key = <nowiki>"人物誌Persona"</nowiki>}} on Google and found the search result contains {{kbd | key = <nowiki>人物誌(Persona)</nowiki>}}, {{kbd | key = <nowiki>人物誌(Persona) </nowiki>}} & {{kbd | key =<nowiki>「人物誌」(persona)</nowiki>}}. | * Searched the keywords e.g. {{kbd | key = <nowiki>"人物誌Persona"</nowiki>}} on Google and found the search result contains {{kbd | key = <nowiki>人物誌(Persona)</nowiki>}}, {{kbd | key = <nowiki>人物誌(Persona) </nowiki>}} & {{kbd | key =<nowiki>「人物誌」(persona)</nowiki>}}. | ||
== Highlight search query | == Highlight search query keywords on resulting pages == | ||
Total 130 ~ 240 characters. ( | Total 130 ~ 240 characters on Google resulting pages. | ||
Input search keywords, and returned the matched paragraph. Using MySQL [http://www.w3resource.com/mysql/string-functions/mysql-substring-function.php SUBSTRING() function], [http://www.w3resource.com/mysql/string-functions/mysql-position-function.php POSITION() function] & [http://www.w3resource.com/mysql/string-functions/mysql-char_length-function.php CHAR_LENGTH() function]. | |||
<pre> | |||
SET @message := "笑傲江湖中嵩山派掌門左冷禪所創掌法,可發出至陰至寒的真氣。左冷禪與任我行比武時,以此功對付吸星大法,使其全身凍僵、天池穴被封;與岳不群比劍奪帥時,左又使出寒冰神掌,與紫霞神功旗鼓相當、不分勝敗。 | |||
原文網址:https://kknews.cc/zh-tw/culture/xzaxbq.html"; | |||
SELECT | |||
@message | |||
, CASE | |||
WHEN POSITION("吸星大法" IN @message) > 0 THEN SUBSTRING(@message | |||
, IF( | |||
POSITION("吸星大法" IN @message) > 0 && | |||
POSITION("吸星大法" IN @message) -10 < 0 | |||
, 1 | |||
, POSITION("吸星大法" IN @message) -10) | |||
, CHAR_LENGTH("吸星大法") + 20 | |||
) | |||
ELSE '' | |||
END AS "scrapbook" | |||
-- Returned result of scrapbook column: Show 10 characters before or after the search keywords. | |||
-- 行比武時,以此功對付吸星大法,使其全身凍僵、天池 | |||
</pre> | |||
<pre> | |||
SET @message := "原文網址:https://kknews.cc/zh-tw/culture/xzaxbq.html"; | |||
SELECT | |||
@message | |||
, CASE | |||
WHEN POSITION("吸星大法" IN @message) > 0 THEN SUBSTRING(@message | |||
, IF( | |||
POSITION("吸星大法" IN @message) > 0 && | |||
POSITION("吸星大法" IN @message) -10 < 0 | |||
, 1 | |||
, POSITION("吸星大法" IN @message) -10) | |||
, CHAR_LENGTH("吸星大法") + 20 | |||
) | |||
ELSE '' | |||
END AS "scrapbook" | |||
-- Returned result of scrapbook column: Show 10 characters before or after the search keywords. | |||
-- [EMPTY] | |||
</pre> | |||
== Ranking factors == | == Ranking factors == | ||
Revision as of 11:28, 28 June 2017
AND
Google search: keyword1 keyword2 same as keyword1 AND keyword2 or keyword1 +keyword2.
(1) The following is exact words search. (2) Replace column_name with your column name
- Google: 易筋經 AND 吸星大法
- MySQL: column_name REGEXP '易筋經' AND column_name REGEXP '吸星大法'
- MySQL: column_name LIKE '%易筋經%' AND column_name LIKE '%吸星大法%' (online demo[1])
- MySQL: IF(LOCATE('易筋經', column_name) > 0) AND IF(LOCATE('吸星大法, column_name) > 0)
- MySQL: column_name LIKE '%易筋經%吸星大法%' AND column_name LIKE '%吸星大法%易筋經%'
Trivial for multiple keywords
OR
Google search: keyword1 OR keyword2
- Google: 易筋經 OR 吸星大法
- MySQL: column_name REGEXP '易筋經' OR column_name REGEXP '吸星大法'
- MySQL: IF(LOCATE('易筋經', column_name) > 0) OR IF(LOCATE('吸星大法, column_name) > 0)
- MySQL: column_name LIKE '%易筋經%' OR column_name LIKE '%吸星大法%' (online demo[2])
NOT
Google search: keyword1 NOT keyword2 same as keyword1 -keyword2
- Google: 易筋經 NOT 吸星大法
- MySQL: column_name REGEXP '易筋經' AND column_name NOT REGEXP '吸星大法' (online demo)
- MySQL: IF(LOCATE('易筋經', column_name) > 0) AND IF(LOCATE('吸星大法, column_name) = 0)
- MySQL: column_name LIKE '%易筋經%' AND column_name NOT LIKE '%吸星大法%'
* wildcard operator
Google * wildcard operator. "Use *, an asterisk character, known as a wildcard, to match one or more words in a phrase" [1] (online demo)
- Google: 狐狸*叫
- MySQL: column_name LIKE '狐狸%叫'[2]
Ignore special characters
Ignore return symbol and span tag
- Searched the keywords e.g. "意法" site:ptt.cc on Google and found the search result contains 意 & 法 located in the nearest but different rows. 意 is at the end of the n-th row. 法 is at the beginning of n+1-th row [3].
Ignore space, Halfwidth and fullwidth symbol (半形字元和全形字元)
- Searched the keywords e.g. "嗎有" on Google and found the search result contains 嗎? 有 & 嗎- 有.
- Searched the keywords e.g. "人物誌Persona" on Google and found the search result contains 人物誌(Persona), 人物誌(Persona) & 「人物誌」(persona).
Highlight search query keywords on resulting pages
Total 130 ~ 240 characters on Google resulting pages.
Input search keywords, and returned the matched paragraph. Using MySQL SUBSTRING() function, POSITION() function & CHAR_LENGTH() function.
SET @message := "笑傲江湖中嵩山派掌門左冷禪所創掌法,可發出至陰至寒的真氣。左冷禪與任我行比武時,以此功對付吸星大法,使其全身凍僵、天池穴被封;與岳不群比劍奪帥時,左又使出寒冰神掌,與紫霞神功旗鼓相當、不分勝敗。
原文網址:https://kknews.cc/zh-tw/culture/xzaxbq.html";
SELECT
@message
, CASE
WHEN POSITION("吸星大法" IN @message) > 0 THEN SUBSTRING(@message
, IF(
POSITION("吸星大法" IN @message) > 0 &&
POSITION("吸星大法" IN @message) -10 < 0
, 1
, POSITION("吸星大法" IN @message) -10)
, CHAR_LENGTH("吸星大法") + 20
)
ELSE ''
END AS "scrapbook"
-- Returned result of scrapbook column: Show 10 characters before or after the search keywords.
-- 行比武時,以此功對付吸星大法,使其全身凍僵、天池
SET @message := "原文網址:https://kknews.cc/zh-tw/culture/xzaxbq.html";
SELECT
@message
, CASE
WHEN POSITION("吸星大法" IN @message) > 0 THEN SUBSTRING(@message
, IF(
POSITION("吸星大法" IN @message) > 0 &&
POSITION("吸星大法" IN @message) -10 < 0
, 1
, POSITION("吸星大法" IN @message) -10)
, CHAR_LENGTH("吸星大法") + 20
)
ELSE ''
END AS "scrapbook"
-- Returned result of scrapbook column: Show 10 characters before or after the search keywords.
-- [EMPTY]
Ranking factors
Possibile factors
- Google PageRank - Wikipedia
- MySQL POSITION() function - w3resource / MySQL LENGTH() function - w3resource where the keywords located.
to explore strange new worlds / related articles:
- MySQL :: MySQL 5.1 Reference Manual :: 12.5.2 Regular Expressions
- regex - MySQL REGEXP word boundaries and double quotes - Stack Overflow keyin column REGEXP "[[:<:]]word[[:>:]]"
- Google 進階搜尋, Punctuation, symbols & operators in search - Search Help
- Yahoo Advanced Web Search
- Advanced search options of bing
- 在 Excel 或 Google 試算表中,布林搜尋多個關鍵字
other search cases: if the column ... (inspired by OutWit)
- contains ____
- does not contain ____
- begins with ____
- does not begins with ____
- ends with ____
- does not ends with ____
- equals to ____
- does not equal ____
references
related news:
| MySQL related news |
|---|
|
Failed to load RSS feed from https://news.google.com.tw/news/feeds?pz=1&cf=all&ned=us&hl=en-US&q=mysql&cf=all&scoring=n&output=rss: Error parsing XML for RSS
|
|
Powered by Google News |