所以,我刚刚开始阅读这篇文章,我以前从未在PHP中实现过搜索。我有几个问题,我想知道:
感谢。
答案 0 :(得分:5)
基本上你需要一个基本索引然后是一个delta索引。增量更新基础中的任何内容。因此,您可以在凌晨1点运行基本索引,然后每隔5分钟更新一次增量。您可以在表或其他数据库中存储时间戳,并控制哪些记录在增量中。
然后,您可以查看sql_query_killlist以删除已删除的内容,请参阅文档。
示例conf可能看起来像这样。
source _user
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass =
sql_db = db
sql_port = 3306
sql_attr_uint = category_id
sql_attr_timestamp = time_posted
}
source user_base : _user
{
sql_query_pre = REPLACE INTO sphinx_lastrun (object_name, object_value) SELECT 'users', @max_stamp:=UNIX_TIMESTAMP(MAX(stamp))-1 FROM users
sql_query = SELECT id, category_id, name, UNIX_TIMESTAMP(stamp) AS stamp FROM users WHERE stamp < FROM_UNIXTIME(@max_stamp)
sql_query_info = SELECT id FROM users WHERE id=$id
}
source user_incr : _user
{
sql_query = SELECT id, category_id, name, UNIX_TIMESTAMP(stamp) AS stamp FROM users WHERE stamp >= (SELECT FROM_UNIXTIME(object_value) FROM sphinx_lastrun WHERE object_name = 'users')
# You'll need sql_query_killlist to get rid of stuff that is deleted. See the docs
sql_query_info = SELECT id FROM users WHERE id=$id
}
index _user
{
docinfo = extern
mlock = 0
morphology = none
min_word_len = 2
charset_type = sbcs
min_prefix_len = 3
enable_star = 1
}
index user_base : _user
{
source = user_base
path = /opt/sphinx/var/data/user_base
}
index user_incr : _user
{
source = user_incr
path = /opt/sphinx/var/data/user_incr
}
index user
{
type = distributed
local = user_base
local = user_incr
}
searchd
{
listen = 3312
log = /opt/sphinx/var/log/searchd/searchd.log
query_log = /opt/sphinx/var/log/searchd/query.log
pid_file = /opt/sphinx/var/log/searchd/searchd.pid
}
答案 1 :(得分:1)
回答你的第一个问题:是的Sphinx带有一个后台运行的守护进程,并在指示时执行搜索。
答案 2 :(得分:0)
您可以使用增量索引方案,请参阅here。