The FACET Feature_MySQL
Sphinx 2.2.3-beta includes a FACET clause which makes faceted search with Sphinx much easier. Now you can do faceted search without thinking about the multi-query optimization technique. This post will point out how the old and new styles differ. Check it out!
FACET
You may have readthis article about faceted search with Sphinx. Forget about it. Things have changed. We’ve implemented aFACET
keyword which will help you write very short facet queries. If you’re not sure what faceted search is, go check out eBay (or, see the example we link to at the bottom of this post). It provides an excellent example of faceted search– your search is supplemented with categories that allow you to drill down into specific “facets” of the result set.
Old vs. New
Previously, with Sphinx, doing something like this required several requests with a specific groupby in each request. Sphinx optimized those using the multi-queries feature.
The new feature is similar to the ol’ multi-queries technique, but uses a new keyword with its own expressions, aliases (i.e. it’s possible to writeFACET x AS y
) and it returns multiple result sets per single request (as a bonus you don’t have to mess with delimiters, i.e. you had to write “mysql --delimiter=# -P 9306 -e "select ...; select ...; select ...;
” to get working multi-queries, otherwise the MySQL client sends 3 separate statements).
So the whole thing becomes essentially ONE single compact query which optimizes search automatically and fetches all result sets in a single pass.
Old syntax (3 result sets):
SELECT * from facetdemo limit 0,10; SELECT GROUPBY(), COUNT(*) FROM facetdemo GROUP BY categories; SELECT GROUPBY(), COUNT(*) FROM facetdemo GROUP BY brand_id; 登录后复制 |
New syntax (3 result sets):
SELECT * FROM facetdemo LIMIT 0,10 FACET categories FACET brand_id; 登录后复制 |
And, here’s a quick example with PHP demonstrating how FACET queries can be run via the standard PDO or the mysqli multi-query API:
$query = "SELECT * FROM facetdemo FACET categories FACET brand_id"; $pdo = new PDO('mysql:host=127.0.0.1;port=9306');$stmt = $pdo->query($query);do {$rowset = $stmt->fetchAll();print_r ($rowset);} while ($stmt->nextRowset()); $mysqli = new mysqli('127.0.0.1', 'test', '', '', 9306);if ($mysqli->multi_query($query)){ do { if ($result = $mysqli->store_result()) { while ($row = $result->fetch_row()) print_r($row); $result->free(); } } while ($mysqli->more_results() && $mysqli->next_result());} 登录后复制 |
Faceted search in action
Take a look atAdrian’s faceting example to get a feel for how it works. He provides examples of both the old and new styles. Then, go take a look atthe codeused to produce this example. Adrian has it on github.
Here’s a preview of the example:
Give it a try! Grab 2.2.3-betahere. If you need some help,contact us– we provide support. And, if you have questions, please ask them.
Happy Sphinxing!
Tags:faceted search,featured,PHP
«May 15, 2014. Sphinx 2.2.3-beta is now available |

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

全表扫描在MySQL中可能比使用索引更快,具体情况包括:1)数据量较小时;2)查询返回大量数据时;3)索引列不具备高选择性时;4)复杂查询时。通过分析查询计划、优化索引、避免过度索引和定期维护表,可以在实际应用中做出最优选择。

InnoDB的全文搜索功能非常强大,能够显着提高数据库查询效率和处理大量文本数据的能力。 1)InnoDB通过倒排索引实现全文搜索,支持基本和高级搜索查询。 2)使用MATCH和AGAINST关键字进行搜索,支持布尔模式和短语搜索。 3)优化方法包括使用分词技术、定期重建索引和调整缓存大小,以提升性能和准确性。

是的,可以在 Windows 7 上安装 MySQL,虽然微软已停止支持 Windows 7,但 MySQL 仍兼容它。不过,安装过程中需要注意以下几点:下载适用于 Windows 的 MySQL 安装程序。选择合适的 MySQL 版本(社区版或企业版)。安装过程中选择适当的安装目录和字符集。设置 root 用户密码,并妥善保管。连接数据库进行测试。注意 Windows 7 上的兼容性问题和安全性问题,建议升级到受支持的操作系统。

聚集索引和非聚集索引的区别在于:1.聚集索引将数据行存储在索引结构中,适合按主键查询和范围查询。2.非聚集索引存储索引键值和数据行的指针,适用于非主键列查询。

文章讨论了流行的MySQL GUI工具,例如MySQL Workbench和PhpMyAdmin,比较了它们对初学者和高级用户的功能和适合性。[159个字符]

MySQL是一个开源的关系型数据库管理系统。1)创建数据库和表:使用CREATEDATABASE和CREATETABLE命令。2)基本操作:INSERT、UPDATE、DELETE和SELECT。3)高级操作:JOIN、子查询和事务处理。4)调试技巧:检查语法、数据类型和权限。5)优化建议:使用索引、避免SELECT*和使用事务。

MySQL 数据库中,用户和数据库的关系通过权限和表定义。用户拥有用户名和密码,用于访问数据库。权限通过 GRANT 命令授予,而表由 CREATE TABLE 命令创建。要建立用户和数据库之间的关系,需创建数据库、创建用户,然后授予权限。
