首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在sphinx中选择sql源查询中的列

如何在sphinx中选择sql源查询中的列
EN

Stack Overflow用户
提问于 2017-03-21 13:04:56
回答 1查看 1.1K关注 0票数 0

我使用sphinx索引器根据mysql中的文档创建字典,但不能将源的sql查询限制在选定的列上。

这是我使用的命令

代码语言:javascript
运行
复制
indexer --buildstops dict.txt 1000 --verbose --print-queries --dump-rows listing_rows --buildfreqs listing_core -c config/development.sphinx.conf

使用development.sphinx.conf中的以下源代码,将不会找到任何文档,并且dict.txt为空

代码语言:javascript
运行
复制
source listing_source {
  type = mysql
  sql_host = mysql
  sql_user = sharetribe
  sql_pass = secret
  sql_db = sharetribe_development
  sql_query = SELECT title AS title, description AS description FROM listings;
}

输出

代码语言:javascript
运行
复制
Sphinx 2.2.10-id64-release (2c212e0)
Copyright (c) 2001-2015, Andrew Aksyonoff
Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file 'config/development.sphinx.conf'...
WARNING: key 'max_matches' was permanently removed from Sphinx configuration. Refer to documentation for details.
WARNING: key 'charset_type' was permanently removed from Sphinx configuration. Refer to documentation for details.
WARNING: key 'enable_star' was permanently removed from Sphinx configuration. Refer to documentation for details.
WARNING: key 'charset_type' was permanently removed from Sphinx configuration. Refer to documentation for details.
WARNING: key 'enable_star' was permanently removed from Sphinx configuration. Refer to documentation for details.
indexing index 'listing_core'...
building stopwords list...
SQL-CONNECT: ok
SQL-QUERY: SELECT title AS title, description AS description FROM listings;: ok
total 0 docs, 0 bytes
total 0.008 sec, 0 bytes/sec, 0.00 docs/sec
total 0 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
total 0 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg

当我将sql_query更改为返回所有列时,索引器将查找文档(2)的预期数量,并将它们添加到字典中。

代码语言:javascript
运行
复制
source listing_source {
  type = mysql
  sql_host = mysql
  sql_user = sharetribe
  sql_pass = secret
  sql_db = sharetribe_development
  sql_query = SELECT * FROM listings;
}

输出:

代码语言:javascript
运行
复制
Sphinx 2.2.10-id64-release (2c212e0)
Copyright (c) 2001-2015, Andrew Aksyonoff
Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file 'config/development.sphinx.conf'...
WARNING: key 'max_matches' was permanently removed from Sphinx configuration. Refer to documentation for details.
WARNING: key 'charset_type' was permanently removed from Sphinx configuration. Refer to documentation for details.
WARNING: key 'enable_star' was permanently removed from Sphinx configuration. Refer to documentation for details.
WARNING: key 'charset_type' was permanently removed from Sphinx configuration. Refer to documentation for details.
WARNING: key 'enable_star' was permanently removed from Sphinx configuration. Refer to documentation for details.
indexing index 'listing_core'...
building stopwords list...
SQL-CONNECT: ok
SQL-QUERY: SELECT * FROM listings;: ok
total 2 docs, 485 bytes
total 0.008 sec, 56303 bytes/sec, 232.18 docs/sec
total 0 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
total 0 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg

如何将查询限制为只返回选定的列?

EN

Stack Overflow用户

回答已采纳

发布于 2017-03-23 17:10:50

sql_query =从列表中选择标题作为标题,将描述作为描述;

不工作,因为它没有一个document_id。添加id列(作为第一个!)而且它应该能工作。您也不需要'AS‘如果使用相同的名称。(*可能有效,因为类似于id的列恰好位于第一位:)

因此,只需确保包含一个id,然后将您的列命名为字段.

代码语言:javascript
运行
复制
sql_query = SELECT id, title, description FROM listings
票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42928029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档