python - django sphinx search 总是没有从查询中得到

标签 python django centos sphinx wsgi

我使用这部分代码从 sphinx 获取文档,但 sphinx 查询总是返回 None。但是,如果我从命令行执行代码,我会得到正确的结果,有什么问题吗?

def search_query(query, offset=0):
    mode = SPH_MATCH_EXTENDED
    host = 'localhost'
    port = 9312
    index = 'rss_item'
    filtercol = 'group_id'
    filtervals = []
    sortby = '-@weights'
    groupby = 'id'
    groupsort = '@group desc'
    limit = 30

    # do query
    cl = SphinxClient()
    cl.SetServer ( host, port )
    cl.SetWeights ( [100, 1] )
    cl.SetMatchMode ( mode )

    #cl.SetSortMode(SPH_SORT_TIME_SEGMENTS)
    if limit:
        cl.SetLimits ( offset, limit, max(limit,1000) )
    res = cl.Query ( query, index )

    docs =[]
    for item in res['matches']:
        docs.append(item['id'])

    return docs

# this is django view
def search(request):
    q = request.GET.get('q', '')
    offset = int(request.GET.get('older', 0))
    docs=search_query(q, offset)

    result = Item.objects.filter(id__in=docs).all()

    objects = dict([(obj.id, obj) for obj in result])
    sorted_objects = [objects[id] for id in docs]

    result = sorted_objects

    return render_to_response('rss/_items.html',
                              {'latest_items':result, 'offset':offset+30,'q':q},
                              context_instance=RequestContext(request))

服务器:centos6, sphinx :2.0.5,django:1.4.2,apache/wsgi

最佳答案

解决问题,关闭 Selinux 并重新启动服务器,我通过以下命令收听 apache 进程:

ps auxw | grep httpd | awk '{print"-p " $2}' | xargs strace

并查看访问 apache 到 sphinx 和 memcache 的权限被拒绝

关于python - django sphinx search 总是没有从查询中得到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13781259/

相关文章:

python - Altair 条件颜色散点图

python - 用于定义选择字段的元组列表中前导下划线的含义?

linux - 监听Linux上的特定端口以访问来自移动设备的数据

linux - 即使路径正确,shell 脚本 cd 也会失败

linux - Google Cloud Compute 上的多个 IP 地址

python - 向量化最近邻计算

python - 如何找出/打印使用哪个版本的协议(protocol)生成了 pickle 文件

python - 将 pigpio 安装到虚拟环境中

Django SQL OR 通过 filter() & Q() : Dynamic?

python - Django ORM 魔法。错误还是功能?