{"id":204047,"date":"2025-05-29T08:57:38","date_gmt":"2025-05-29T00:57:38","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204047\/"},"modified":"2025-05-29T08:57:38","modified_gmt":"2025-05-29T00:57:38","slug":"orator%e4%b8%ad%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e5%a4%9a%e6%9d%a1%e4%bb%b6like%e6%9f%a5%e8%af%a2%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204047\/","title":{"rendered":"Orator\u4e2d\u5982\u4f55\u5b9e\u73b0\u591a\u6761\u4ef6LIKE\u67e5\u8be2\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Orator\u4e2d\u5982\u4f55\u5b9e\u73b0\u591a\u6761\u4ef6LIKE\u67e5\u8be2\uff1f<\/h1>\n<p>\u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662f\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aOrator\u4e2d\u5982\u4f55\u5b9e\u73b0\u591a\u6761\u4ef6LIKE\u67e5\u8be2\uff1f\u300b<\/span>\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729902999671c3997c3190.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>orator\u4e2d\u7684\u591a\u6761\u4ef6like\u67e5\u8be2<\/strong><\/p>\n<p>orator\u662fpython\u7684\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u6570\u636e\u5e93\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\uff08orm\uff09\u6846\u67b6\u3002\u5728\u539f\u751fsql\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528or\uff08\u6216\uff09\u8fd0\u7b97\u7b26\u6784\u9020\u591a\u4e2alike\u67e5\u8be2\u6761\u4ef6\u3002\u672c\u6587\u5c06\u63a2\u8ba8\u5982\u4f55\u5728orator\u4e2d\u7f16\u5199\u8fd9\u6837\u7684\u67e5\u8be2\u3002<\/p>\n<p><strong>\u539f\u751fsql\u67e5\u8be2<\/strong><\/p>\n<pre>select * from `think_user` where  (`name` like '%think%' or `name` like '%php%')<\/pre>\n<p><strong>orator\u67e5\u8be2<\/strong><\/p>\n<ul>\n<li><strong>\u5355\u4e2a\u5173\u952e\u8bcd\u67e5\u8be2<\/strong><\/li>\n<\/ul>\n<p>\u4f7f\u7528like\u65b9\u6cd5\u8fdb\u884c\u5355\u4e2a\u6761\u4ef6\u7684like\u67e5\u8be2\u975e\u5e38\u7b80\u5355\uff1a<\/p>\n<pre>db.table('full_text').where('title', 'like', f'%{word}%').get()<\/pre>\n<ul>\n<li><strong>\u591a\u4e2a\u5173\u952e\u8bcd\u67e5\u8be2<\/strong><\/li>\n<\/ul>\n<p>\u5bf9\u4e8e\u591a\u4e2a\u5173\u952e\u8bcd\u7684like\u67e5\u8be2\uff0corator\u65e0\u6cd5\u4f7f\u7528or_where\u65b9\u6cd5\u3002\u56e0\u6b64\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u65b9\u6cd51\uff1a\u4f7f\u7528\u591a\u6b21\u8d4b\u503c<\/strong><\/p>\n<pre>#\u5b9e\u73b0and\u903b\u8f91\nsearch = ['%word1%', '%word2%', '%word3%', ...]\ninfo = db.table('full_text')\nfor s in search:\n    info = info.where('title', 'like', s)\nresult = info.get()\n\n#\u5b9e\u73b0or\u903b\u8f91\nsearch = ['%word1%', '%word2%', '%word3%', ...]\ninfo = db.table('full_text')\nfor s in search:\n    if search.index(s) == 0:\n        info = info.where('title', 'like', s)\n    else:\n        info = info.or_where('title', 'like', s)\nresult = info.get()<\/pre>\n<p><strong>\u65b9\u6cd52\uff1a\u4f7f\u7528\u539f\u751fsql<\/strong><\/p>\n<pre>query = \"SELECT * FROM `full_text` WHERE  (`title` LIKE '%think%' OR `title` LIKE '%php%')\"\nresult = DB.select(DB.raw(query)).get()<\/pre>\n<p>\u867d\u7136orator\u7f3a\u4e4f\u5bf9\u591a\u6761\u4ef6like\u67e5\u8be2\u7684\u76f4\u63a5\u652f\u6301\uff0c\u4f46\u4f7f\u7528\u591a\u6b21\u8d4b\u503c\u6216\u539f\u751fsql\u4ecd\u7136\u53ef\u4ee5\u5b9e\u73b0\u3002\u4f46\u662f\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u79cd\u65b9\u6cd5\u53ef\u80fd\u4f1a\u5bfc\u81f4\u91cd\u590d\u67e5\u8be2\uff0c\u4ece\u800c\u964d\u4f4e\u67e5\u8be2\u6548\u7387\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300aOrator\u4e2d\u5982\u4f55\u5b9e\u73b0\u591a\u6761\u4ef6LIKE\u67e5\u8be2\uff1f\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1aphp \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Orator\u4e2d\u5982\u4f55\u5b9e\u73b0\u591a\u6761\u4ef6LI&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204047","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204047","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204047"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204047\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}