-1

我在 Windows 上开发站点,但是当我尝试添加搜索时,我遇到了 Sphinx 和 Haystack+Xapian 的太多问题。可能的解决方案是去 Linux,但我不想改变我的工作环境。您为 Windows 推荐什么搜索库/服务器/等?您使用过哪个版本、存储库、教程?也许您可以编写自己的迷你教程?我对这个问题感到非常沮丧,并且几天都无法前进。

4

1 回答 1

0

最后我让 Sphinx 工作。在多个表中搜索仍然存在问题,但我相信这是可以解决的。

有用的链接:
如何使用 MySQL 和 PHP 在 XAMPP for Windows 7 上安装和实现 Sphinx Search

教程:在 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
}

在 app 文件夹中创建 \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 回答