如何在 sphinx 中 sql 源查询中的 select 列
How to select columns in sql query of source in sphinx
我正在使用 sphinx 索引器根据我的 mysql 数据库中的文档创建字典,但我无法将源的 sql 查询限制为选定的列。
这是我使用的命令
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 为空
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;
}
输出
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 更改为 return 时,索引器会找到预期数量的文档 (2) 并将它们添加到字典中。
source listing_source {
type = mysql
sql_host = mysql
sql_user = sharetribe
sql_pass = secret
sql_db = sharetribe_development
sql_query = SELECT * FROM listings;
}
输出:
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
如何将查询限制为仅 return 个选定的列?
sql_query = SELECT title AS title, description AS description FROM listings;
不起作用,因为它没有 document_id。添加一个 id 列(作为第一个!)它应该可以工作。如果使用相同的名称,您也不需要 'AS'。 (* 可能有效,因为像列这样的 id 恰好是第一个 :)
所以只需确保包含一个 ID,然后将您想要的列命名为 fields ...
sql_query = SELECT id, title, description FROM listings
我正在使用 sphinx 索引器根据我的 mysql 数据库中的文档创建字典,但我无法将源的 sql 查询限制为选定的列。
这是我使用的命令
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 为空
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;
}
输出
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 更改为 return 时,索引器会找到预期数量的文档 (2) 并将它们添加到字典中。
source listing_source {
type = mysql
sql_host = mysql
sql_user = sharetribe
sql_pass = secret
sql_db = sharetribe_development
sql_query = SELECT * FROM listings;
}
输出:
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
如何将查询限制为仅 return 个选定的列?
sql_query = SELECT title AS title, description AS description FROM listings;
不起作用,因为它没有 document_id。添加一个 id 列(作为第一个!)它应该可以工作。如果使用相同的名称,您也不需要 'AS'。 (* 可能有效,因为像列这样的 id 恰好是第一个 :)
所以只需确保包含一个 ID,然后将您想要的列命名为 fields ...
sql_query = SELECT id, title, description FROM listings