Skip to content

Instantly share code, notes, and snippets.

@CBoJI
Created September 28, 2012 07:51
Show Gist options
  • Save CBoJI/3798516 to your computer and use it in GitHub Desktop.
Save CBoJI/3798516 to your computer and use it in GitHub Desktop.
sphinx
http://sphinxsearch.com/downloads/ - скачать tar.gz
tar -xzf
cd
1)
./configure --without-mysql --with-pgsql --prefix=/usr/local/sphinx --with-pgsql-libs=/usr/lib/postgresql-9.1/ --with-pgsql-includes=/usr/include/postgresql-9.1/
2) make
3) make install
4) cd /usr/local/sphinx/etc/
создаем sphinx.conf
прописываем
searchd
{
# какой порт и какой протокол "слушает" служба
listen = 3312
# файл с логами
log = /home/drobservis_new/logs/searchd.log
# файл с логами поисковых запросов
query_log = /home/drobservis_new/logs/query.log
# PID file, searchd process ID file name
# mandatory
pid_file = /home/drobservis_new/logs/searchd.pid
}
5) скачать django-sphinx
в settings.py проекта прописать
SPHINX_API_VERSION = 0x116
DATABASE_ENGINE = 'postgresql'
DATABASE_NAME = 'drobservis'
DATABASE_USER = 'drobservis'
DATABASE_PASSWORD = 'Zqh%YX^7s&_P!^k'
DATABASE_PORT = '5432'
DATABASE_HOST = 'localhost'
6)
from djangosphinx.models import SphinxSearch
class MyModel(models.Model):
search = SphinxSearch() # optional: defaults to db_table
# If your index name does not match MyModel._meta.db_table
# Note: You can only generate automatic configurations from the ./manage.py script
# if your index name matches.
search = SphinxSearch('index_name')
# Or maybe we want to be more.. specific
searchdelta = SphinxSearch(
index='index_name delta_name',
weights={
'name': 100,
'description': 10,
'tags': 80,
},
mode='SPH_MATCH_ALL',
rankmode='SPH_RANK_NONE',
)
7) manage.py generate_sphinx_config app
8) скопировать сгенерированный конфиг в sphinx.conf
PS morphology = stem_enru (изменить в конфиге)
( пароль бд придется руками поправить, так как с ошибкой(скорее всего) скопирует из проекта)
9) indexer --all
(FATAL: failed to open /var/data/pages.spl: No such file or directory, will not index. Try --rotate option.
-создать папку дата)
10) (env)localhost etc # /usr/local/sphinx/bin/searchd
PS order - зарезервированное слово sql, поэтому в конфиге сфинкса его ставим в кавычки
item = MyModel.search.query(u'дробилка')
print item
print item._sphinx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment