Sphinx 和 PHP 的一些问题

Some issues with Sphinx and PHP

情况如下:

我的数据库中有一个很大的 table - 3.6 GB 和 1,7M 行。从 table 选择限制和偏移量非常慢,并且经常导致错误 504。Table 是 MyISAM,有多个索引,将被更新。

这就是为什么我决定使用 Sphinx 来列出 table 的内容 - 在某些情况下没有查询(所有行),在某些情况下有查询 - 它就像一个魅力。速度惊人。

但这就是问题所在 - 没有查询,只有前 1,000 个结果被 returned。即使我用 $this->SetLimits(41, 24); 调用它,它应该 return 我得到 id 从 9841008 的结果,但我得到的最后一个结果是 id 1,000。我尝试更改 /etc/sphinxsearch/sphinx.conf 中的值,重新启动服务,但没有成功。 另外,这是个好主意吗?我的意思是,它会显着降低性能吗?有关如何执行此操作的任何建议?

还有一个问题:

在我的 sphinx.conf 中,我选择了要用于 search/order 的列,它们都出现在 [matches] 部分中。因为我不使用它们,所以它们只占用内存并且(我猜)会在一定程度上降低性能。我只在我的应用程序中使用 id。是否可以通过这些列 search/order,但将它们从 [matches] 中排除?

我的sphinx.conf

source test {

  type          = mysql

  sql_host      = localhost
  sql_user      = root
  sql_pass      = password
  sql_db        = database
  sql_port      = 3306

  sql_query     = \
  SELECT id, name,  UNIX_TIMESTAMP(date) as date, views, rating \
  FROM table \
  WHERE active = 1

  sql_field_string      = name
  sql_attr_timestamp    = date
  sql_attr_uint         = views
  sql_attr_uint         = rating

  sql_query_info        = SELECT * FROM table WHERE id=$id

}

index test {

  source            = test
  path              = /var/lib/sphinxsearch/data/test
  docinfo           = extern
  charset_type      = utf-8

}

searchd {

  listen            = 9312
  log               = /var/log/sphinxsearch/searchd.log
  query_log         = /var/log/sphinxsearch/query.log
  read_timeout      = 5
  max_children      = 30
  pid_file          = /var/run/sphinxsearch/searchd.pid
  max_matches       = 10000 # I tried changing this to 10,000 - no result
  seamless_rotate   = 1
  preopen_indexes   = 1
  unlink_old        = 1
  binlog_path       = /var/lib/sphinxsearch/data

}

这是因为还有每个查询的最大匹配设置,默认为 1000。

在 sphinx.conf 你可以设置类似

max_matches = 10000 

或者,将 max_matches 添加到您的查询中

$this->SetLimits(41, 24, 10000);

Note that there are two places where max_matches limit is enforced. Per-query limit is controlled by this API call, but there also is per-server limit controlled by max_matches setting in the config file. To prevent RAM usage abuse, server will not allow to set per-query limit higher than the per-server limit.

对于第二部分,请查看 ->SetSelect() 函数。