{"id":1068885,"date":"2024-12-31T16:47:10","date_gmt":"2024-12-31T08:47:10","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1068885.html"},"modified":"2024-12-31T16:47:12","modified_gmt":"2024-12-31T08:47:12","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e5%81%9a%e6%9c%ac%e5%9c%b0%e6%90%9c%e7%b4%a2%e5%bc%95%e6%93%8e","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1068885.html","title":{"rendered":"\u5982\u4f55\u7528Python\u505a\u672c\u5730\u641c\u7d22\u5f15\u64ce"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/15636ca6-70de-4409-9139-1e4f1a7c0fc1.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\u5982\u4f55\u7528Python\u505a\u672c\u5730\u641c\u7d22\u5f15\u64ce\" \/><\/p>\n<p><p> <strong>\u4f7f\u7528Python\u6784\u5efa\u672c\u5730\u641c\u7d22\u5f15\u64ce\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a\u6570\u636e\u6536\u96c6\u4e0e\u9884\u5904\u7406\u3001\u5efa\u7acb\u7d22\u5f15\u3001\u67e5\u8be2\u5904\u7406\u3001\u6392\u540d\u7b97\u6cd5\u3001\u5c55\u793a\u7ed3\u679c\u3002<\/strong> \u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u5e76\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u5b9e\u73b0\u6bcf\u4e00\u4e2a\u6b65\u9aa4\uff0c\u5e2e\u52a9\u4f60\u6784\u5efa\u4e00\u4e2a\u529f\u80fd\u9f50\u5168\u7684\u672c\u5730\u641c\u7d22\u5f15\u64ce\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u6570\u636e\u6536\u96c6\u4e0e\u9884\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u6570\u636e\u6536\u96c6\u548c\u9884\u5904\u7406\u662f\u6784\u5efa\u672c\u5730\u641c\u7d22\u5f15\u64ce\u7684\u7b2c\u4e00\u6b65\u3002\u6570\u636e\u53ef\u4ee5\u6765\u81ea\u672c\u5730\u6587\u4ef6\u7cfb\u7edf\u3001\u6570\u636e\u5e93\u3001\u7f51\u7ad9\u722c\u866b\u7b49\u3002\u65e0\u8bba\u6570\u636e\u6765\u6e90\u5982\u4f55\uff0c\u9884\u5904\u7406\u90fd\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u4e00\u6b65\uff0c\u4ee5\u786e\u4fdd\u6570\u636e\u7684\u4e00\u81f4\u6027\u548c\u53ef\u7528\u6027\u3002<\/p>\n<\/p>\n<p><h4>\u6570\u636e\u6536\u96c6<\/h4>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6587\u4ef6\u7cfb\u7edf<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>os<\/code>\u6a21\u5757\u904d\u5386\u672c\u5730\u6587\u4ef6\u7cfb\u7edf\uff0c\u6536\u96c6\u6587\u672c\u6587\u4ef6\u6216\u5176\u4ed6\u683c\u5f0f\u7684\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>def collect_files(directory):<\/p>\n<p>    file_paths = []<\/p>\n<p>    for root, dirs, files in os.walk(directory):<\/p>\n<p>        for file in files:<\/p>\n<p>            if file.endswith(&quot;.txt&quot;):  # \u5047\u8bbe\u6211\u4eec\u53ea\u5904\u7406\u6587\u672c\u6587\u4ef6<\/p>\n<p>                file_paths.append(os.path.join(root, file))<\/p>\n<p>    return file_paths<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u5e93<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528SQLAlchemy\u7b49ORM\u5de5\u5177\u4ece\u6570\u636e\u5e93\u4e2d\u63d0\u53d6\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sqlalchemy import create_engine<\/p>\n<p>from sqlalchemy.orm import sessionmaker<\/p>\n<p>def collect_data_from_db(connection_string, query):<\/p>\n<p>    engine = create_engine(connection_string)<\/p>\n<p>    Session = sessionmaker(bind=engine)<\/p>\n<p>    session = Session()<\/p>\n<p>    result = session.execute(query)<\/p>\n<p>    data = result.fetchall()<\/p>\n<p>    session.close()<\/p>\n<p>    return data<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7f51\u9875\u722c\u866b<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528Scrapy\u6216BeautifulSoup\u7b49\u5de5\u5177\u4ece\u7f51\u7ad9\u6536\u96c6\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>from bs4 import BeautifulSoup<\/p>\n<p>def collect_data_from_web(url):<\/p>\n<p>    response = requests.get(url)<\/p>\n<p>    soup = BeautifulSoup(response.text, &#39;html.parser&#39;)<\/p>\n<p>    texts = soup.find_all(&#39;p&#39;)  # \u5047\u8bbe\u6211\u4eec\u53ea\u63d0\u53d6\u6bb5\u843d\u6587\u672c<\/p>\n<p>    return [text.get_text() for text in texts]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h4>\u6570\u636e\u9884\u5904\u7406<\/h4>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6e05\u6d17\u6570\u636e<\/strong>\uff1a\u53bb\u9664HTML\u6807\u7b7e\u3001\u7279\u6b8a\u5b57\u7b26\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>def clean_text(text):<\/p>\n<p>    text = re.sub(r&#39;&lt;[^&gt;]+&gt;&#39;, &#39;&#39;, text)  # \u53bb\u9664HTML\u6807\u7b7e<\/p>\n<p>    text = re.sub(r&#39;\\W+&#39;, &#39; &#39;, text)  # \u53bb\u9664\u7279\u6b8a\u5b57\u7b26<\/p>\n<p>    return text.lower()  # \u8f6c\u4e3a\u5c0f\u5199<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5206\u8bcd\u4e0e\u8bcd\u5e72\u63d0\u53d6<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528NLTK\u6216spaCy\u7b49\u5de5\u5177\u8fdb\u884c\u5206\u8bcd\u548c\u8bcd\u5e72\u63d0\u53d6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import nltk<\/p>\n<p>from nltk.stem import PorterStemmer<\/p>\n<p>from nltk.tokenize import word_tokenize<\/p>\n<p>nltk.download(&#39;punkt&#39;)<\/p>\n<p>stemmer = PorterStemmer()<\/p>\n<p>def preprocess_text(text):<\/p>\n<p>    words = word_tokenize(text)<\/p>\n<p>    return [stemmer.stem(word) for word in words]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u5efa\u7acb\u7d22\u5f15<\/h3>\n<\/p>\n<p><p>\u5efa\u7acb\u7d22\u5f15\u662f\u641c\u7d22\u5f15\u64ce\u7684\u6838\u5fc3\u90e8\u5206\u3002\u7d22\u5f15\u4f7f\u5f97\u641c\u7d22\u64cd\u4f5c\u53ef\u4ee5\u5728\u5408\u7406\u7684\u65f6\u95f4\u5185\u5b8c\u6210\u3002\u901a\u5e38\u4f7f\u7528\u5012\u6392\u7d22\u5f15\u6765\u63d0\u9ad8\u641c\u7d22\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h4>\u5012\u6392\u7d22\u5f15<\/h4>\n<\/p>\n<p><p>\u5012\u6392\u7d22\u5f15\u662f\u4e00\u79cd\u5c06\u6587\u6863\u4e2d\u7684\u8bcd\u6620\u5c04\u5230\u5305\u542b\u8be5\u8bcd\u7684\u6587\u6863\u5217\u8868\u7684\u6570\u636e\u7ed3\u6784\u3002\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>collections<\/code>\u6a21\u5757\u5b9e\u73b0\u5012\u6392\u7d22\u5f15\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from collections import defaultdict<\/p>\n<p>def build_inverted_index(docs):<\/p>\n<p>    inverted_index = defaultdict(list)<\/p>\n<p>    for doc_id, text in docs.items():<\/p>\n<p>        for word in preprocess_text(text):<\/p>\n<p>            inverted_index[word].append(doc_id)<\/p>\n<p>    return inverted_index<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u67e5\u8be2\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u67e5\u8be2\u5904\u7406\u662f\u7528\u6237\u8f93\u5165\u67e5\u8be2\u540e\uff0c\u641c\u7d22\u5f15\u64ce\u5982\u4f55\u89e3\u91ca\u5e76\u5904\u7406\u8fd9\u4e9b\u67e5\u8be2\u7684\u8fc7\u7a0b\u3002\u901a\u5e38\u5305\u62ec\u67e5\u8be2\u89e3\u6790\u3001\u67e5\u8be2\u6269\u5c55\u7b49\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h4>\u67e5\u8be2\u89e3\u6790<\/h4>\n<\/p>\n<p><p>\u5c06\u7528\u6237\u8f93\u5165\u7684\u67e5\u8be2\u89e3\u6790\u4e3a\u4e00\u7ec4\u8bcd\u6216\u77ed\u8bed\uff0c\u5e76\u8fdb\u884c\u9884\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def parse_query(query):<\/p>\n<p>    return preprocess_text(clean_text(query))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u67e5\u8be2\u6269\u5c55<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u540c\u4e49\u8bcd\u6269\u5c55\u67e5\u8be2\uff0c\u589e\u52a0\u641c\u7d22\u7ed3\u679c\u7684\u8986\u76d6\u9762\u3002\u53ef\u4ee5\u4f7f\u7528NLTK\u7684WordNet\u5e93\u8fdb\u884c\u540c\u4e49\u8bcd\u6269\u5c55\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from nltk.corpus import wordnet<\/p>\n<p>def expand_query(query):<\/p>\n<p>    expanded_query = set(query)<\/p>\n<p>    for word in query:<\/p>\n<p>        for syn in wordnet.synsets(word):<\/p>\n<p>            for lemma in syn.lemmas():<\/p>\n<p>                expanded_query.add(lemma.name())<\/p>\n<p>    return list(expanded_query)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u6392\u540d\u7b97\u6cd5<\/h3>\n<\/p>\n<p><p>\u6392\u540d\u7b97\u6cd5\u51b3\u5b9a\u4e86\u641c\u7d22\u7ed3\u679c\u7684\u6392\u5e8f\u3002\u5e38\u7528\u7684\u6392\u540d\u7b97\u6cd5\u5305\u62ecTF-IDF\u3001BM25\u7b49\u3002<\/p>\n<\/p>\n<p><h4>TF-IDF<\/h4>\n<\/p>\n<p><p>TF-IDF\uff08Term Frequency-Inverse Document Frequency\uff09\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u6587\u672c\u76f8\u5173\u6027\u5ea6\u91cf\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>def compute_tf_idf(docs, inverted_index):<\/p>\n<p>    tf_idf = defaultdict(lambda: defaultdict(float))<\/p>\n<p>    doc_count = len(docs)<\/p>\n<p>    for term, doc_ids in inverted_index.items():<\/p>\n<p>        idf = math.log(doc_count \/ len(doc_ids))<\/p>\n<p>        for doc_id in doc_ids:<\/p>\n<p>            tf = docs[doc_id].count(term) \/ len(docs[doc_id])<\/p>\n<p>            tf_idf[doc_id][term] = tf * idf<\/p>\n<p>    return tf_idf<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u6392\u540d\u6587\u6863<\/h4>\n<\/p>\n<p><p>\u6839\u636e\u67e5\u8be2\u8bcd\u7684TF-IDF\u503c\u5bf9\u6587\u6863\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def rank_documents(query, tf_idf):<\/p>\n<p>    scores = defaultdict(float)<\/p>\n<p>    for term in query:<\/p>\n<p>        for doc_id, tf_idf_score in tf_idf.items():<\/p>\n<p>            scores[doc_id] += tf_idf_score[term]<\/p>\n<p>    return sorted(scores.items(), key=lambda item: item[1], reverse=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u5c55\u793a\u7ed3\u679c<\/h3>\n<\/p>\n<p><p>\u6700\u540e\u4e00\u6b65\u662f\u5c06\u641c\u7d22\u7ed3\u679c\u5c55\u793a\u7ed9\u7528\u6237\u3002\u53ef\u4ee5\u4f7f\u7528Flask\u7b49\u6846\u67b6\u6784\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Web\u754c\u9762\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528Flask\u5c55\u793a\u641c\u7d22\u7ed3\u679c<\/h4>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Flask<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install flask<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efaFlask\u5e94\u7528<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask, request, render_template<\/p>\n<p>app = Flask(__name__)<\/p>\n<p>@app.route(&#39;\/&#39;)<\/p>\n<p>def index():<\/p>\n<p>    return render_template(&#39;index.html&#39;)<\/p>\n<p>@app.route(&#39;\/search&#39;, methods=[&#39;POST&#39;])<\/p>\n<p>def search():<\/p>\n<p>    query = request.form[&#39;query&#39;]<\/p>\n<p>    parsed_query = parse_query(query)<\/p>\n<p>    expanded_query = expand_query(parsed_query)<\/p>\n<p>    ranked_docs = rank_documents(expanded_query, tf_idf)<\/p>\n<p>    results = [docs[doc_id] for doc_id, score in ranked_docs]<\/p>\n<p>    return render_template(&#39;results.html&#39;, query=query, results=results)<\/p>\n<p>if __name__ == &#39;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&#39;:<\/p>\n<p>    app.run(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efaHTML\u6a21\u677f<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>templates\/index.html<\/code><\/li>\n<\/ul>\n<p><pre><code class=\"language-html\">&lt;!doctype html&gt;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>    &lt;title&gt;Search Engine&lt;\/title&gt;<\/p>\n<p>&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>    &lt;form action=&quot;\/search&quot; method=&quot;post&quot;&gt;<\/p>\n<p>        &lt;input type=&quot;text&quot; name=&quot;query&quot;&gt;<\/p>\n<p>        &lt;input type=&quot;submit&quot; value=&quot;Search&quot;&gt;<\/p>\n<p>    &lt;\/form&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><code>templates\/results.html<\/code><\/li>\n<\/ul>\n<p><pre><code class=\"language-html\">&lt;!doctype html&gt;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>    &lt;title&gt;Search Results&lt;\/title&gt;<\/p>\n<p>&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>    &lt;h1&gt;Search Results for &quot;{{ query }}&quot;&lt;\/h1&gt;<\/p>\n<p>    &lt;ul&gt;<\/p>\n<p>    {% for result in results %}<\/p>\n<p>        &lt;li&gt;{{ result }}&lt;\/li&gt;<\/p>\n<p>    {% endfor %}<\/p>\n<p>    &lt;\/ul&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u516d\u3001\u4f18\u5316\u4e0e\u6269\u5c55<\/h3>\n<\/p>\n<p><p>\u6784\u5efa\u4e00\u4e2a\u57fa\u672c\u7684\u672c\u5730\u641c\u7d22\u5f15\u64ce\u53ea\u662f\u5f00\u59cb\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u8fdb\u4e00\u6b65\u4f18\u5316\u548c\u6269\u5c55\uff1a<\/p>\n<\/p>\n<p><h4>\u4f18\u5316\u7d22\u5f15\u6784\u5efa<\/h4>\n<\/p>\n<ul>\n<li><strong>\u5e76\u884c\u5904\u7406<\/strong>\uff1a\u4f7f\u7528\u591a\u7ebf\u7a0b\u6216\u591a\u8fdb\u7a0b\u52a0\u901f\u7d22\u5f15\u6784\u5efa\u3002<\/li>\n<li><strong>\u538b\u7f29\u7d22\u5f15<\/strong>\uff1a\u4f7f\u7528\u538b\u7f29\u7b97\u6cd5\u51cf\u5c11\u7d22\u5f15\u5927\u5c0f\u3002<\/li>\n<\/ul>\n<p><h4>\u6539\u8fdb\u67e5\u8be2\u5904\u7406<\/h4>\n<\/p>\n<ul>\n<li><strong>\u62fc\u5199\u7ea0\u9519<\/strong>\uff1a\u4f7f\u7528Levenshtein\u8ddd\u79bb\u7b49\u7b97\u6cd5\u8fdb\u884c\u62fc\u5199\u7ea0\u9519\u3002<\/li>\n<li><strong>\u81ea\u7136\u8bed\u8a00\u5904\u7406<\/strong>\uff1a\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u8fdb\u884c\u66f4\u590d\u6742\u7684\u67e5\u8be2\u7406\u89e3\u3002<\/li>\n<\/ul>\n<p><h4>\u589e\u5f3a\u6392\u540d\u7b97\u6cd5<\/h4>\n<\/p>\n<ul>\n<li><strong>\u4f7f\u7528BM25<\/strong>\uff1aBM25\u662f\u4e00\u79cd\u6539\u8fdb\u7684TF-IDF\u7b97\u6cd5\uff0c\u901a\u5e38\u8868\u73b0\u66f4\u597d\u3002<\/li>\n<li><strong>\u7ed3\u5408\u7528\u6237\u884c\u4e3a<\/strong>\uff1a\u4f7f\u7528\u70b9\u51fb\u7387\u3001\u505c\u7559\u65f6\u95f4\u7b49\u7528\u6237\u884c\u4e3a\u6570\u636e\u6539\u8fdb\u6392\u540d\u3002<\/li>\n<\/ul>\n<p><h4>\u6269\u5c55\u641c\u7d22\u529f\u80fd<\/h4>\n<\/p>\n<ul>\n<li><strong>\u652f\u6301\u591a\u79cd\u6587\u4ef6\u683c\u5f0f<\/strong>\uff1a\u5904\u7406PDF\u3001Word\u7b49\u591a\u79cd\u6587\u4ef6\u683c\u5f0f\u3002<\/li>\n<li><strong>\u591a\u8bed\u8a00\u652f\u6301<\/strong>\uff1a\u652f\u6301\u591a\u79cd\u8bed\u8a00\u7684\u641c\u7d22\u3002<\/li>\n<li><strong>\u589e\u91cf\u7d22\u5f15<\/strong>\uff1a\u652f\u6301\u5b9e\u65f6\u6570\u636e\u66f4\u65b0\u3002<\/li>\n<\/ul>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u6784\u5efa\u4e00\u4e2a\u672c\u5730\u641c\u7d22\u5f15\u64ce\u662f\u4e00\u4e2a\u590d\u6742\u4f46\u6781\u5177\u6311\u6218\u6027\u7684\u4efb\u52a1\u3002\u901a\u8fc7\u6570\u636e\u6536\u96c6\u4e0e\u9884\u5904\u7406\u3001\u5efa\u7acb\u7d22\u5f15\u3001\u67e5\u8be2\u5904\u7406\u3001\u6392\u540d\u7b97\u6cd5\u3001\u5c55\u793a\u7ed3\u679c\u7b49\u6b65\u9aa4\uff0c\u53ef\u4ee5\u6784\u5efa\u4e00\u4e2a\u529f\u80fd\u9f50\u5168\u7684\u672c\u5730\u641c\u7d22\u5f15\u64ce\u3002\u8fdb\u4e00\u6b65\u7684\u4f18\u5316\u4e0e\u6269\u5c55\u53ef\u4ee5\u63d0\u5347\u641c\u7d22\u5f15\u64ce\u7684\u6027\u80fd\u548c\u7528\u6237\u4f53\u9a8c\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u4e3a\u4f60\u63d0\u4f9b\u4e00\u4e2a\u5168\u9762\u7684\u6307\u5bfc\uff0c\u5e2e\u52a9\u4f60\u6210\u529f\u6784\u5efa\u81ea\u5df1\u7684\u672c\u5730\u641c\u7d22\u5f15\u64ce\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5f00\u59cb\u4f7f\u7528Python\u6784\u5efa\u672c\u5730\u641c\u7d22\u5f15\u64ce\uff1f<\/strong><br \/>\u5728\u6784\u5efa\u672c\u5730\u641c\u7d22\u5f15\u64ce\u65f6\uff0c\u9996\u5148\u9700\u8981\u9009\u62e9\u9002\u5408\u7684\u5e93\u548c\u5de5\u5177\u3002\u53ef\u4ee5\u4f7f\u7528\u5982Whoosh\u3001Elasticsearch\u7b49\u5e93\u6765\u5904\u7406\u6587\u672c\u7d22\u5f15\u548c\u641c\u7d22\u529f\u80fd\u3002\u63a5\u4e0b\u6765\uff0c\u6536\u96c6\u548c\u6574\u7406\u9700\u8981\u7d22\u5f15\u7684\u6570\u636e\uff0c\u901a\u5e38\u662f\u4ece\u6587\u4ef6\u7cfb\u7edf\u6216\u6570\u636e\u5e93\u4e2d\u63d0\u53d6\u4fe1\u606f\u3002\u63a5\u7740\uff0c\u521b\u5efa\u4e00\u4e2a\u7d22\u5f15\uff0c\u5e76\u4e3a\u5176\u914d\u7f6e\u9002\u5f53\u7684\u641c\u7d22\u7b97\u6cd5\u548c\u6392\u540d\u673a\u5236\uff0c\u6700\u540e\u5b9e\u73b0\u4e00\u4e2a\u7528\u6237\u754c\u9762\uff0c\u4ee5\u4fbf\u8fdb\u884c\u641c\u7d22\u548c\u5c55\u793a\u7ed3\u679c\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5b9e\u73b0\u641c\u7d22\u5f15\u64ce\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u6027\u80fd\u95ee\u9898\uff1f<\/strong><br \/>\u5728\u5b9e\u73b0\u641c\u7d22\u5f15\u64ce\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6027\u80fd\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u8003\u8651\u56e0\u7d20\u3002\u5904\u7406\u5927\u91cf\u6570\u636e\u65f6\uff0c\u5fc5\u987b\u4f18\u5316\u7d22\u5f15\u8fc7\u7a0b\uff0c\u786e\u4fdd\u641c\u7d22\u67e5\u8be2\u7684\u54cd\u5e94\u65f6\u95f4\u5c3d\u53ef\u80fd\u77ed\u3002\u53ef\u4ee5\u901a\u8fc7\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97\u3001\u4f7f\u7528\u5185\u5b58\u7f13\u5b58\u6280\u672f\u3001\u4ee5\u53ca\u9009\u62e9\u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784\u6765\u63d0\u9ad8\u6027\u80fd\u3002\u6b64\u5916\uff0c\u5b9a\u671f\u5bf9\u7d22\u5f15\u8fdb\u884c\u7ef4\u62a4\u548c\u66f4\u65b0\u4e5f\u662f\u63d0\u5347\u6027\u80fd\u7684\u91cd\u8981\u63aa\u65bd\u3002<\/p>\n<p><strong>\u5982\u4f55\u786e\u4fdd\u672c\u5730\u641c\u7d22\u5f15\u64ce\u7684\u7ed3\u679c\u51c6\u786e\u6027\u548c\u76f8\u5173\u6027\uff1f<\/strong><br \/>\u51c6\u786e\u6027\u548c\u76f8\u5173\u6027\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u6765\u63d0\u5347\u3002\u9996\u5148\uff0c\u826f\u597d\u7684\u7d22\u5f15\u7ed3\u6784\u548c\u6587\u6863\u5206\u6790\u662f\u57fa\u7840\uff0c\u786e\u4fdd\u6570\u636e\u88ab\u6b63\u786e\u89e3\u6790\u548c\u5b58\u50a8\u3002\u5176\u6b21\uff0c\u53ef\u4ee5\u5b9e\u73b0\u52a0\u6743\u673a\u5236\uff0c\u5bf9\u4e0d\u540c\u6587\u6863\u6839\u636e\u5176\u91cd\u8981\u6027\u8d4b\u4e88\u4e0d\u540c\u7684\u6743\u91cd\u3002\u6b64\u5916\uff0c\u91c7\u7528\u81ea\u7136\u8bed\u8a00\u5904\u7406\u6280\u672f\uff0c\u5982\u8bcd\u5e72\u63d0\u53d6\u3001\u540c\u4e49\u8bcd\u5904\u7406\u7b49\uff0c\u80fd\u591f\u8fdb\u4e00\u6b65\u63d0\u9ad8\u641c\u7d22\u7ed3\u679c\u7684\u76f8\u5173\u6027\u3002\u7528\u6237\u53cd\u9988\u673a\u5236\u4e5f\u662f\u4e00\u4e2a\u6709\u6548\u7684\u624b\u6bb5\uff0c\u901a\u8fc7\u5206\u6790\u7528\u6237\u70b9\u51fb\u884c\u4e3a\u6765\u4f18\u5316\u641c\u7d22\u7b97\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528Python\u6784\u5efa\u672c\u5730\u641c\u7d22\u5f15\u64ce\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a\u6570\u636e\u6536\u96c6\u4e0e\u9884\u5904\u7406\u3001\u5efa\u7acb\u7d22\u5f15\u3001\u67e5\u8be2\u5904\u7406\u3001\u6392\u540d [&hellip;]","protected":false},"author":3,"featured_media":1068894,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1068885"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1068885"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1068885\/revisions"}],"predecessor-version":[{"id":1068898,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1068885\/revisions\/1068898"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1068894"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1068885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1068885"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1068885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}