{"id":114573,"date":"2019-05-22T10:57:29","date_gmt":"2019-05-22T02:57:29","guid":{"rendered":"http:\/\/www.fagao.me\/?p=114573"},"modified":"2019-05-22T10:57:29","modified_gmt":"2019-05-22T02:57:29","slug":"%e5%8e%9f%e5%88%9b%e6%8a%95%e7%a8%bf-%e5%a6%82%e4%bd%95%e4%b8%badjango%e6%b7%bb%e5%8a%a0%e4%b8%ad%e6%96%87%e6%90%9c%e7%b4%a2%e6%9c%8d%e5%8a%a1","status":"publish","type":"post","link":"https:\/\/www.fagao.me\/p\/114573.htm","title":{"rendered":"\u539f\u521b\u6295\u7a3f | \u5982\u4f55\u4e3aDjango\u6dfb\u52a0\u4e2d\u6587\u641c\u7d22\u670d\u52a1"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.fagao.me\/images\/uploads\/F040.jpg\" alt=\"\"><\/p>\n<div class=\"focusup\"><\/div>\n<p><strong><span><strong><span>\u4e91\u8c46<\/span><\/strong>\u8d34\u5fc3\u63d0\u9192\uff0c\u672c\u6587\u9605\u8bfb\u65f6\u95f47\u5206\u949f<\/span><\/strong><\/p>\n<p>\u5728\u4f7f\u7528python\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5fc5\u7136\u4f1a\u8bbe\u8ba1\u5230\u5982\u4f55\u521b\u5efaweb\u5e94\u7528\uff0c\u800c\u641c\u7d22\u529f\u80fd\u5374\u6700\u4e3a\u5e38\u89c1\uff0c\u8be5\u6587\u6863\u5305\u542b\u4e86\u5982\u4f55\u6574\u5408haystack\uff0celasticsearch\u3001ik\u4e2d\u6587\u5206\u8bcd\u5230django\u5e94\u7528\u4e2d\u3002<\/p>\n<blockquote>\n<p><span><strong>\u6d4b\u8bd5\u5e94\u7528\u7248\u672c<\/strong><\/span><\/p>\n<\/blockquote>\n<blockquote>\n<p><span><strong>\u5b89\u88c5<\/strong><\/span><\/p>\n<\/blockquote>\n<p><strong>python\u5305\u5b89\u88c5<\/strong><\/p>\n<\/p>\n<p><strong>elasticsearch\u5b89\u88c5<\/strong><\/p>\n<p>elasticsearch\u57fa\u4e8ejava\uff0c\u6240\u4ee5\u9700\u8981\u5148\u5b89\u88c5java\u3002<\/p>\n<\/p>\n<p><strong>elasticsearch-analysis-ik\u5b89\u88c5<\/strong><\/p>\n<p><strong>\u5b89\u88c5maven<\/strong><\/p>\n<\/p>\n<p>\u6ce8\u610f\u5b89\u88c5\u5fc5\u987b\u4f7f\u7528\u5bf9\u5e94\u7684\u7248\u672c\uff0c\u6d4b\u8bd5\u4e5f\u662f\u5982\u6b64\uff0c\u6bd4\u5982\u6b64\u5904\u4f7f\u75281.9.5\u7248\u672c\u3002<\/p>\n<p><strong>\u4e0b\u8f7d\uff0c\u5b89\u88c5elasticsearch-analysis-ik<\/strong><\/p>\n<\/p>\n<p><strong>\u6ce8\u610f<\/strong><\/p>\n<p>\u5728\u4f7f\u7528\u4e2d\u4e0d\u7528\u523b\u610f\u9009\u62e9\u9ad8\u7248\u672c\u7684elasticsearch\uff0c\u53ef\u4ee5\u6709\u6548\u907f\u514d\u7248\u672c\u4e0d\u517c\u5bb9\u3002<\/p>\n<p>\u53e6\u5916\u4e00\u5b9a\u8981\u6ce8\u610f\u4f60\u4f7f\u7528\u7684elasticsearch\u7248\u672c\u662f\u5426\u548celasticsearch-analysis-ik\u5bf9\u5e94\u3002<\/p>\n<\/p>\n<blockquote>\n<p><span><strong>\u5f00\u59cb\u4f7f\u7528<\/strong><\/span><\/p>\n<\/blockquote>\n<p><strong>\u7b80\u5355\u7248\u672c<\/strong><\/p>\n<p>\u4f7f\u7528whoosh\u4f5c\u4e3a\u540e\u7aef\u7d22\u5f15\u5b58\u50a8(\u57fa\u4e8e\u6587\u4ef6\u7cfb\u7edf)\uff0c\u8be5\u64cd\u4f5c\u53c2\u8003\u5b98\u65b9\u6587\u6863\u5373\u53ef\u3002<\/p>\n<p>\u52a0\u5165\u4e2d\u6587\u7684\u652f\u6301<\/p>\n<\/p>\n<p>1\u3001\u5c06\u6587\u4ef6haystack\u4e2d\u7684whoosh_backend.py\uff08\u8be5\u6587\u4ef6\u8def\u5f84\u4e3apython\u5b89\u88c5\u8def\u5f84\u4e0b\/lib\/python2.7.6\/site-packages\/haystack\/backends\/whoosh_backend.py\uff09\u62f7\u8d1d\u5230\u4f60\u521b\u5efa\u7684\u5e94\u7528\u4e0b\u9762\uff0c\u5e76\u91cd\u547d\u540d\u4e3awhoosh_cn_backend.py\uff0c\u4f8b\u5982blog\/whoosh_cn_backend.py\u3002<\/p>\n<p>\u7f16\u8f91blog\/whoosh_cn_backend.py\u5bfc\u5165\u4e2d\u6587\u5206\u6790\u5e93ChineseAnalyzer<\/p>\n<p>\u4fee\u6539blog\/whoosh_cn_backend.py\u5927\u6982163\u884c\u4f4d\u7f6e<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.fagao.me\/images\/uploads\/F035.png\" alt=\"\"><\/p>\n<p>2\u3001\u5728settings.py\u4e2d\u4fee\u6539\u4e4b\u524d\u4f7f\u7528\u7684\u9ed8\u8ba4\u7684whooshEngine\u4e3a\u4fee\u6539\u540e\u7684WhooshEngine\u3002<\/p>\n<\/p>\n<p>3\u3001\u91cd\u5efa\u7d22\u5f15python manage.py rebuild_index\uff0c\u5728\u8fdb\u884c\u641c\u7d22\u4e2d\u6587\u8bd5\u8bd5\u5427\u3002<\/p>\n<p><strong>\u6ce8\u610f\u7d22\u5f15\u7684\u81ea\u52a8\u66f4\u65b0\uff1a<\/strong><\/p>\n<p>\u9ed8\u8ba4\u7d22\u5f15\u6ca1\u6709\u81ea\u52a8\u66f4\u65b0\uff0c\u90a3\u4e48\u6bcf\u5f53\u6709\u65b0\u6570\u636e\u6dfb\u52a0\u5230\u6570\u636e\u5e93\uff0c\u5c31\u8981\u624b\u52a8\u6267\u884cupdate_index\u547d\u4ee4\u662f\u4e0d\u79d1\u5b66\u7684\u3002<\/p>\n<p>\u81ea\u52a8\u66f4\u65b0\u7d22\u5f15\u7684\u6700\u7b80\u5355\u65b9\u6cd5\u5728settings.py\u6dfb\u52a0\u4e00\u4e2a\u4fe1\u53f7\u3002<\/p>\n<blockquote>\n<p><span><strong>\u5347\u7ea7\u7248\u672c<\/strong><\/span><\/p>\n<\/blockquote>\n<p>\u7531\u4e8ewhoosh\u662f\u57fa\u4e8e\u6587\u4ef6\u7cfb\u7edf\u7684\uff0c\u6240\u6709\u5728\u7d22\u5f15\u6570\u636e\u91cf\u8fc7\u5927\u65f6\u5fc5\u7136\u5f15\u8d77\u6027\u80fd\u95ee\u9898\u3002<\/p>\n<p>\u4ece\u5b98\u65b9\u63cf\u8ff0\u4e5f\u53ef\u4ee5\u770b\u5f97\u51faWhoosh is pure Python, so it\u2019s a great option for getting started quickly and for development, though it does work for small scale live deployments\u3002<\/p>\n<p>\u9700\u8981\u63d0\u524d\u5b89\u88c5\u597delasticsearch\u548celasticsearch-analysis-ik\uff0c\u5e76\u901a\u8fc7\u6d4b\u8bd5\u3002<\/p>\n<p>\u5728\u4e4b\u524d\u7684\u9879\u76ee\u7684\u57fa\u7840\u4e0a\u4fee\u6539settings.py<\/p>\n<p>\u524d\uff1a<\/p>\n<\/p>\n<p><strong>\u521b\u5efa\u7d22\u5f15\u540d<\/strong><\/p>\n<\/p>\n<p>\u5982\u679crebuild_index\u4e2d\u51fa\u9519\uff0c\u8bf7\u4ed4\u7ec6\u67e5\u770b\u51fa\u9519\u65e5\u5fd7\u3002<\/p>\n<blockquote>\n<p><span><strong>\u90e8\u5206\u4ee3\u7801<\/strong><\/span><\/p>\n<\/blockquote>\n<p><strong>urls.py\uff1a<\/strong><\/p>\n<\/p>\n<p><strong>views.py:<\/strong><\/p>\n<\/p>\n<p><span><strong>\u603b\u7ed3\uff1a<\/strong><\/span><\/p>\n<p>\u901a\u8fc7\u5bf9\u6bd4\u4e24\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u53d1\u73b0\uff1a<\/p>\n<p>whoosh\u4f7f\u7528jieba\u5206\u8bcd\u505a\u5904\u7406\uff0c\u7136\u540e\u57fa\u4e8e\u6587\u4ef6\u5b58\u50a8\u3002<\/p>\n<p>elasticsearch\u4f7f\u7528ik\u5206\u8bcd\u4f5c\u4e3a\u63d2\u4ef6\uff0c\u63d0\u4f9b\u4e2d\u6587\u5206\u8bcd\u7684\u80fd\u529b\uff0chaystack\u901a\u8fc7\u4e0b\u5c42\u62bd\u8c61\uff0c\u5728\u4e0d\u4fee\u6539\u4ee3\u7801\u7684\u540c\u65f6\u505a\u5230\u4e86\u53ef\u4ee5\u9009\u62e9\u4e0d\u540c\u540e\u7aef\u7d22\u5f15\u5b58\u50a8\u7684\u76ee\u7684\u3002<\/p>\n<p>\u672c\u6587\u4f5c\u8005\uff1a\u6211\u8fd8\u662f\u7334\u5b50<\/p>\n<p>\u5982\u679c\u4f60\u89c9\u5f97\u8fd9\u7bc7\u6587\u7ae0\u8fd8\u4e0d\u9519\uff0c\u8bf7\u901a\u8fc7\u4e0b\u65b9\u6536\u6b3e\u7801\u5411\u4f5c\u8005\u8fdb\u884c\u8f6c\u8d26\u6253\u8d4f\uff1a<\/p>\n<div class=\"articleend\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e91\u8c46\u8d34\u5fc3\u63d0\u9192\uff0c\u672c\u6587\u9605\u8bfb\u65f6\u95f47\u5206\u949f \u5728\u4f7f\u7528python\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5fc5\u7136\u4f1a\u8bbe\u8ba1\u5230\u5982\u4f55\u521b\u5efaweb\u5e94\u7528\uff0c\u800c\u641c\u7d22\u529f\u80fd\u5374\u6700\u4e3a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[188],"class_list":["post-114573","post","type-post","status-publish","format-standard","hentry","category-news","tag-188"],"_links":{"self":[{"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/posts\/114573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/comments?post=114573"}],"version-history":[{"count":0,"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/posts\/114573\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/media?parent=114573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/categories?post=114573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fagao.me\/p\/wp-json\/wp\/v2\/tags?post=114573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}