我的PySolr代码位于
之下filter_queries = []
facet_fields = []
for key, value in request.GET._iterlists():
if(key != 'Rows' and key != 'Sort' and key != 'Facet' and key != 'FacetFields' ):
filter_queries.append(key + ':' + request.GET[key])
else:
if(key == 'Rows'):
rows = request.GET['Rows']
if(key == 'Sort'):
sort = request.GET['Sort']
if(key == 'Facet'):
facet = request.GET['Facet']
if(key == 'FacetFields'):
facet_fields = request.GET['FacetFields'].split(",")
if(key == 'Start'):
start = request.GET['Start']
params = {
'fq': filter_queries,
'facet': facet,
'facet.field': facet_fields,
'rows': rows,
'sort': sort,
'start':start,
}
try:
results = solr.search(q='*', **params)
documents = json.dumps(results, default=lambda o: o.__dict__)
except Exception as e:
# handles SOLR invalid queries
documents = json.dumps({'error': 1, 'reason': str(e)})
return HttpResponse(documents)
当我传递?CityId = 3156
它的工作正常时,但现在我需要为CityId传递两个值(例如solr query url ?q=CityId:3156+OR+CityId:2278
)如何在PySolr中实现这一点?
答案 0 :(得分:1)
我正在使用AJAX来处理请求,但Solr的所有API的语法都是相同的。如果你想在一个字段上进行多个查询,你应该使用括号,如下所示:
CityId:(3156 + OR + 2278)
这应该可以解决问题。
答案 1 :(得分:1)
您可以只编写
之类的查询CityId:(3156 + OR + 2278)
或者,您可以正常编写查询,在参数中设置 q.op 参数
query = 'CityId: 3156 2278'
params = {
'fq': ...,
'facet': ...,
'facet.field':...,
'rows': ...,
'sort': ...,
'start':...,
'q.op': 'OR'
}