Sphinxql - 在 PHP 中使用 Sphinxql 而不使用 sphinxapi.php 时如何使用具有顺序的查询
Sphinxql - How to use query having order by while using Sphinxql in PHP without using sphinxapi.php
我一直在使用 mysql FTS,但最近切换到 sphinx 进行测试。
在 centos 7 上安装了 sphinx
Linux production 3.10.0-123.8.1.el7.x86_64 #1 GNU/Linux
sphinx.conf
source content_src1
{
type = mysql
sql_host = localhost
sql_user =
sql_pass =
sql_db = t_prod2
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT content.record_num, \
content.title, \
content.category, \
content.upload_date, \
content.comments_count, \
content.verified, \
content.uploader, \
content.size \
FROM content WHERE enabled = 1
sql_attr_uint = record_num
sql_attr_string = title
}
index content_index1
{
source = content_src1
path = /var/lib/sphinx/content_index1
morphology = stem_en
min_word_len = 1
min_prefix_len = 0
min_infix_len = 1
docinfo = extern
}
我正在使用 php 连接 sphinxql 和 运行 查询,像这样
$sphinxql = @mysqli_connect($sphinxql_host.':'.$sphinxql_port,'','');
$sphinxql_query = "SELECT id FROM $sphinx_index WHERE MATCH('".mysqli_real_escape_string($prod1,$q)."') LIMIT $from,$max_results";
简单查询工作正常,即没有任何按条件排序的查询。
但是当我尝试 运行 sql 具有排序依据的查询时,sphinx 抛出错误。
即
查询及其错误。
SELECT id FROM $sphinx_index WHERE MATCH('".mysqli_real_escape_string($prod1,$q)."') ORDER BY title DESC LIMIT $from,$max_results
index content_index1: sort-by attribute 'title' not found
再试一次,我用@field name 替换了字段名
SELECT id FROM $sphinx_index WHERE MATCH('".mysqli_real_escape_string($prod1,$q)."') ORDER BY @title DESC LIMIT $from,$max_results
sphinxql: syntax error, unexpected USERVAR, expecting IDENT (or 55 other tokens) near '@title DESC LIMIT 0,25'
table 按标题、类别、upload_date、大小、验证等字段排序
那么我如何在我的 sphinxql 查询中使用 order by
更新 1
我已经设法 运行 查询 "not having order by" ,但是 "order by" 的查询不能正常工作,不会给出错误,给出结果集,但是如果我改变排序的方向属性,结果集不会改变。
更新的字段和属性如下。
sql_field_string = title
sql_field_string = og_name
sql_field_string = hash
sql_field_string = keywords
sql_attr_timestamp = upload_date_timestamp
sql_attr_uint = category
sql_attr_uint = comments_count
sql_attr_bool = verified
sql_attr_bigint = size
您是否尝试过将该列用作 sql_attr_string?
http://sphinxsearch.com/docs/current.html#conf-sql-attr-string
您至少需要版本 2.0.1 才能在此类属性上使用 ORDER BY 子句:
Starting from 2.0.1-beta string attributes can be used for sorting and grouping(ORDER BY, GROUP BY, WITHIN GROUP ORDER BY).
我一直在使用 mysql FTS,但最近切换到 sphinx 进行测试。
在 centos 7 上安装了 sphinx
Linux production 3.10.0-123.8.1.el7.x86_64 #1 GNU/Linux
sphinx.conf
source content_src1
{
type = mysql
sql_host = localhost
sql_user =
sql_pass =
sql_db = t_prod2
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT content.record_num, \
content.title, \
content.category, \
content.upload_date, \
content.comments_count, \
content.verified, \
content.uploader, \
content.size \
FROM content WHERE enabled = 1
sql_attr_uint = record_num
sql_attr_string = title
}
index content_index1
{
source = content_src1
path = /var/lib/sphinx/content_index1
morphology = stem_en
min_word_len = 1
min_prefix_len = 0
min_infix_len = 1
docinfo = extern
}
我正在使用 php 连接 sphinxql 和 运行 查询,像这样
$sphinxql = @mysqli_connect($sphinxql_host.':'.$sphinxql_port,'','');
$sphinxql_query = "SELECT id FROM $sphinx_index WHERE MATCH('".mysqli_real_escape_string($prod1,$q)."') LIMIT $from,$max_results";
简单查询工作正常,即没有任何按条件排序的查询。 但是当我尝试 运行 sql 具有排序依据的查询时,sphinx 抛出错误。
即 查询及其错误。
SELECT id FROM $sphinx_index WHERE MATCH('".mysqli_real_escape_string($prod1,$q)."') ORDER BY title DESC LIMIT $from,$max_results
index content_index1: sort-by attribute 'title' not found
再试一次,我用@field name 替换了字段名
SELECT id FROM $sphinx_index WHERE MATCH('".mysqli_real_escape_string($prod1,$q)."') ORDER BY @title DESC LIMIT $from,$max_results
sphinxql: syntax error, unexpected USERVAR, expecting IDENT (or 55 other tokens) near '@title DESC LIMIT 0,25'
table 按标题、类别、upload_date、大小、验证等字段排序
那么我如何在我的 sphinxql 查询中使用 order by
更新 1
我已经设法 运行 查询 "not having order by" ,但是 "order by" 的查询不能正常工作,不会给出错误,给出结果集,但是如果我改变排序的方向属性,结果集不会改变。
更新的字段和属性如下。
sql_field_string = title
sql_field_string = og_name
sql_field_string = hash
sql_field_string = keywords
sql_attr_timestamp = upload_date_timestamp
sql_attr_uint = category
sql_attr_uint = comments_count
sql_attr_bool = verified
sql_attr_bigint = size
您是否尝试过将该列用作 sql_attr_string?
http://sphinxsearch.com/docs/current.html#conf-sql-attr-string
您至少需要版本 2.0.1 才能在此类属性上使用 ORDER BY 子句:
Starting from 2.0.1-beta string attributes can be used for sorting and grouping(ORDER BY, GROUP BY, WITHIN GROUP ORDER BY).