Python django sphinx搜索始终无法从查询中获取任何内容
我使用这部分代码从sphinx获取文档,但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
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的权限被拒绝