Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django sphinx搜索始终无法从查询中获取任何内容_Python_Django_Centos_Sphinx_Wsgi - Fatal编程技术网

Python django sphinx搜索始终无法从查询中获取任何内容

Python django sphinx搜索始终无法从查询中获取任何内容,python,django,centos,sphinx,wsgi,Python,Django,Centos,Sphinx,Wsgi,我使用这部分代码从sphinx获取文档,但sphinx查询始终不返回任何文档。但若我从命令行执行代码,我会得到正确的结果,有什么错 def search_query(query, offset=0): mode = SPH_MATCH_EXTENDED host = 'localhost' port = 9312 index = 'rss_item' filtercol = 'group_id' filtervals = [] sortby

我使用这部分代码从sphinx获取文档,但sphinx查询始终不返回任何文档。但若我从命令行执行代码,我会得到正确的结果,有什么错

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的权限被拒绝