gpt4 book ai didi

php - Sphinxql - 如何在不使用 sphinxapi.php 的情况下在 PHP 中使用 Sphinxql 时使用具有顺序的查询

转载 作者:IT老高 更新时间:2023-10-29 00:17:41 27 4
gpt4 key购买 nike

我一直在使用 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 并运行查询,.like this

$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";

简单的查询工作正常,即没有任何按条件排序的查询。但是当我尝试运行具有 order by 的 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替换了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'

表格按标题、类别、上传日期、大小、已验证等字段排序

那么我如何在我的 sphinxql 查询中使用 order by


更新 1

我已经设法运行“没有排序依据”的查询,但是具有“排序依据”的查询不能正常工作,不会给出错误,给出结果集,但是如果我改变按属性排序的方向,结果集不会变化。

更新的字段和属性是一样的。

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).

关于php - Sphinxql - 如何在不使用 sphinxapi.php 的情况下在 PHP 中使用 Sphinxql 时使用具有顺序的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30259359/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com