Pythontr

husonet | Tarih: 16.05.2012

python sphinxapi

Merhaba,

Kurulum için
/makale.py?tid=129

Bu tanımlar versiyona göre değişebilir
http://code.google.com/p/sphinxsearch/source/list?path=/trunk/api/sphinxapi.php&start=2014

Bu örnek python için hazırlanmıştır.

import sphinxapi
DEBUG = 0

#------------------------------------------------------------------------------
# sphinxsearch connect kurar
def sphinx_connect():
try:
SPH_MATCH_ALL = 0
client = sphinxapi.SphinxClient()
client.SetServer('127.0.0.1', 3312)
client.SetMatchMode(SPH_MATCH_ALL)
except Exception, err:
if DEBUG:
raise
else:
print(str(err))
return client

#------------------------------------------------------------------------------
# sphinxsearch arama yapar
def sphinx_search(sKeyword, sIndx):
try:
total_found = 0
client = sphinx_connect()
client.SetFilter('KATEGORI_ID', [1,2,3,4,5,6,7,8,9,10,11,12,13,14]);
dizi = client.Query(sKeyword, sIndx)
# print dizi
total_found = dizi['total_found']
print 'tr:' + sKeyword + ':' + str(total_found)
except Exception, err:
if DEBUG:
raise
else:
print(str(err))
return total_found