-1

Windows でサイトを開発していますが、検索を追加しようとすると、Sphinx と Haystack+Xapian で問題が多すぎます。考えられる解決策は Linux に移行することですが、作業環境を変更したくありません。Windowsに推奨する検索ライブラリ/サーバー/などは何ですか? どのバージョン、リポジトリ、チュートリアルを使用しましたか? たぶん、あなた自身のミニチュートリアルを書くことができますか? 私はこの問題に本当にイライラしており、数日間先に進むことができません。

4

1 に答える 1

0

ついに私はSphinxを動作させました。複数のテーブルを検索することにはまだ問題がありますが、これは解決できると思います。

便利なリンク:
MySQLとPHPを使用してXAMPP forWindows7にSphinxSearchをインストールして実装する方法

チュートリアル:Windowsへのインストール

WindowsへのSphinxのインストール

次のスニペットでは、システム上のパスが使用されています。

views.pyの検索機能:

def search(request):
    from sphinxapi import SphinxClient, SPH_MATCH_ANY, SPH_SORT_RELEVANCE
    S = request.GET['search']
    client = SphinxClient()
    client.SetServer('127.0.0.1', 9312)
    #client.SetSelect("*, AVG(price) AS avgprice")
    client.SetMatchMode(SPH_MATCH_ANY)
    client.SetSortMode(SPH_SORT_RELEVANCE)
    client.SetFieldWeights({'header': 20, 'text': 10})
    result = client.Query(S, '*')
    matches = result["matches"]
    ids = [match["id"] for match in matches]
    article = {"header": "Search results", "text": ""}
    if ids != []:
        objects = Main.objects.filter(pk__in = ids)
        for object in objects:
            url = request.build_absolute_uri(object.get_absolute_url())
            article["text"] += "<a href=" + url + ">" + object.header + "</a>" + "\n"
        ResponseDict = {"articles": [article]}
    else:
        ResponseDict = {"articles": []}
    return render_to_response("index.html", ResponseDict, 
        context_instance = RequestContext(request))

sphinx.conf(... \ Sphinx \ binフォルダーにあります):

source src1
{
    type = pgsql
    sql_host = localhost
    sql_user = <db user>
    sql_pass = <pwd>
    sql_db = <db name>
    sql_port = 5432
    sql_query = \
        SELECT id, header, text \
        FROM app_main
    sql_query_info = SELECT * FROM app_main WHERE id=$id
    sql_attr_uint = source_id
}


source src2
{
    type = pgsql
    sql_host = localhost
    sql_user = <db user>
    sql_pass = <pwd>
    sql_db = <db name>
    sql_port = 5432
    sql_query = \
        SELECT id, header, text \
        FROM app_comment
    sql_query_info = SELECT * FROM app_comment WHERE id=$id
    sql_attr_uint = source_id
}


index test1
{
    source = src1
    source = src2
    path = D:/blizzard/Projects/Python/Web/moz455/app/sphinx/data/test1
    docinfo = extern
    charset_type = utf-8
}


index testrt
{
    type = rt
    rt_mem_limit = 32M
    path = D:/blizzard/Projects/Python/Web/moz455/app/sphinx/data/testrt
    charset_type = utf-8
    rt_field = title
    rt_field = content
    rt_attr_uint = gid
}


indexer
{
    mem_limit = 32M
}


searchd
{
    listen = 127.0.0.1:9312
    log = D:/blizzard/Projects/Python/Web/moz455/app/sphinx/log/searchd.log
    query_log = D:/blizzard/Projects/Python/Web/moz455/app/sphinx/log/query.log
    read_timeout = 5
    max_children = 30
    pid_file = D:/blizzard/Projects/Python/Web/moz455/app/sphinx/log/searchd.pid
    max_matches = 1000
    seamless_rotate = 1
    preopen_indexes = 1
    unlink_old = 1
    workers = threads # for RT to work
    binlog_path = D:/blizzard/Projects/Python/Web/moz455/app/sphinx/data
}

アプリフォルダに\sphinx、\ sphinx \ data、\ sphinx \ logフォルダを作成し、コマンドでインデックスを作成すると、検索が可能になります

D:/Old/Sphinx/bin/indexer --config D:/Old/Sphinx/bin/sphinx.conf --all

コマンドで検索を開始します

D:/Old/Sphinx/bin/searchd --config D:/Old/Sphinx/bin/sphinx.conf
于 2012-09-20T05:31:28.903 に答える