-1

I develop site on Windows, but when I tried to add search, I encountered too many problems with Sphinx and Haystack+Xapian. Possible solution is to go to Linux, but I don't want to change my working environment. What search library/server/etc do you recommend for Windows? Which version, repository, tutorials have you used? Maybe you can wrote your own mini-tutorial? I really frustrated with this problem and cannot step forward for several days.

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
DSblizzard
  • 4,007
  • 7
  • 48
  • 76
  • “Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, [describe the problem](http://meta.stackexchange.com/q/139399/) and what has been done so far to solve it.” [What topics can I ask about here?](http://stackoverflow.com/help/on-topic) – Anil Jan 24 '14 at 19:07

1 Answers1

0

Finally I got Sphinx to work. Still problems with searching in multiple tables but this is solvable I believe.

Useful links:
How to install and implement Sphinx Search on XAMPP for Windows 7 with MySQL and PHP

Tutorial: Installing on Windows

Installing Sphinx on Windows

In the following snippets paths on my system are used.

Search function in 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 (which is in ...\Sphinx\bin folder):

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
}

Search is available after creating \sphinx, \sphinx\data and \sphinx\log folders in app folder, indexing with command

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

and starting searchd with command

D:/Old/Sphinx/bin/searchd --config D:/Old/Sphinx/bin/sphinx.conf
DSblizzard
  • 4,007
  • 7
  • 48
  • 76