代码之家  ›  专栏  ›  技术社区  ›  Srikar Appalaraju Tonetel

Sphinx搜索引擎和pythonapi

  •  8
  • Srikar Appalaraju Tonetel  · 技术社区  · 14 年前

    使用cpp./search binary时-

    ./search test
    
    1. document=1, weight=1, group_id=1, date_added=Sat Sep 11 07:42:38 2010, title=2
        id=1
        group_id=1
        group_id2=5
        date_added=2010-09-11 07:42:38
        title=test one
        content=this is my test document number one. also checking search within phrases.
    

    >>> import sphinxapi
    >>> client = sphinxapi.SphinxClient()
    >>> client.SetServer('127.0.0.1', 9312)
    >>> client.Query('test')
    {'status': 0, 'matches': [{'id': 1, 'weight': 1, 'attrs': {'date_added': 1284171158, 'group_id': 1, 'title': 2}}, {'id': 2, 'weight': 1, 'attrs': {'date_added': 1284171158, 'group_id': 1, 'title': 3}}, {'id': 4, 'weight': 1, 'attrs': {'date_added': 1284171158, 'group_id': 2, 'title': 1}}], 'fields': ['content'], 'time': '0.022', 'total_found': 3, 'warning': '', 'attrs': [['group_id', 1], ['date_added', 2], ['title', 3]], 'words': [{'docs': 6, 'hits': 6, 'word': 'test'}], 'error': '', 'total': 3}
    

    2 回复  |  直到 14 年前
        1
  •  4
  •   tmg_tt    13 年前

    source YOUR_SOURCE
    {
    sql_field_string = title
    sql_field_string = content
    

    它将索引这些字段的数据,并将这些字段存储为字符串属性,这样您就可以在结果集中获得它们,而无需额外的SQL查询。

        2
  •  7
  •   taufikedys    8 年前

    顺便说一句,官方的SphinxSearch API几乎没有更新,实际上可以使用MySQL驱动程序/模块(例如pymysql)。下面是一个例子:

    import pymysql
    db = pymysql.connect(host='127.0.0.1',port=9301,user='',passwd='',charset='utf8',db='')
    cur = db.cursor()
    qry='SELECT id,weight() FROM idx_name WHERE MATCH(\'"your Query"/1\') LIMIT 10 OPTION ranker=SPH04'
    cur.execute(qry);row = cur.fetchall()
    print(row)
    cur.close();db.close()  
    
    推荐文章