PINQ-查询数据集-简介

PINQ,灵感来源于.NET的LINQ,为PHP提供了强大的查询能力,允许开发者在数组/迭代器和外部数据源之间进行统一的查询。在SQL不足以胜任复杂查询的情况下,如分面搜索,PINQ通过其简洁的API简化了多步骤数据操作。本文介绍了PINQ的基本用法和在PHP应用中的实现,展示了如何使用PINQ进行过滤、排序、分组和聚合,以模拟电子商务网站中的分面搜索功能。
摘要由CSDN通过智能技术生成

You may have heard of LINQ (Language-Integrated Query), a “set of features introduced in Visual Studio 2008 that extends powerful query capabilities to the language syntax of C# and Visual Basic”.

您可能听说过LINQ (语言集成查询),这是“ Visual Studio 2008中引入的一组功能,将强大的查询功能扩展到C#和Visual Basic的语言语法”。

It provides necessary interfaces and syntax to perform various queries on a given dataset so that operations like filtering, sorting, grouping, aggregating, etc can be performed.

它提供了必要的接口和语法,可以对给定的数据集执行各种查询,以便可以执行诸如过滤,排序,分组,聚合等操作。

PINQ (PHP Integrated Query) is “based off the .NET’s Linq, and unifies querying across arrays/iterators and external data sources, in a single readable and concise fluent API”. (Excerpted from PINQ’s official site)

PINQ(PHP集成查询)“基于.NET的Linq,并通过单个可读且简洁的API统一了跨阵列/迭代器和外部数据源的查询”。 (摘自PINQ的官方网站 )

为什么要使用另一种查询语言? (Why another query language?)

PHPers are very much comfortable with executing queries with either raw SQL statements or via ORM. We select the data from a database, process it and display it in a chosen format (say, a table form). If we need another set of data, we issue another statement, process the returned dataset and display it.

PHPer非常适合使用原始SQL语句或通过ORM执行查询。 我们从数据库中选择数据,进行处理并以选定的格式(例如表格形式)显示。 如果需要另一组数据,则发出另一条语句,处理返回的数据集并显示它。

In normal cirucumstances, this process is both sufficient and efficient.

在正常情况下,此过程既充分又有效。

But there are cases where this process simply won’t work. Take, for example, a typical e-Commerce website. The user enters one search keyword (say, “router”) and the site displays every matching item. The initial search may only search items with their description, category or tags containing the keyword. Next, the user will start to fine tune the search results by selecting a brand, a price range, etc.

但是在某些情况下,此过程根本行不通。 以一个典型的电子商务网站为例。 用户输入一个搜索关键字(例如“路由器”),该站点将显示每个匹配的项目。 初始搜索只能搜索具有其描述,类别或包含关键字的标签的项目。 接下来,用户将开始通过选择品牌,价格范围等来微调搜索结果。

This fine tuning process is called “faceted” search. Some database engines (like SOLR) have this capability built in (as described in this series: Using Solarium for SOLR Search) but obviously MySQL does not come with this functionality.

这种微调过程称为“分面”搜索。 一些数据库引擎(如SOLR)具有内置的此功能(如本系列中所述: 使用Solarium进行SOLR搜索 ),但显然MySQL并未提供此功能。

That does not mean, however, that MySQL can’t provide such features. After all, it is all about constructing a new SQL statement and fetching the data again. This has some disadvantages, however:

但是,这并不意味着MySQL无法提供此类功能。 毕竟,这都是关于构造新SQL语句并再次获取数据的。 但是,这有一些缺点:

  1. The criteria of the SQL statement, i.e., the “where” and/or “group by” part, can get very complicated after SQL construction.

    SQL语句的条件,即“ where”和/或“ group by”部分,在构建SQL之后会变得非常复杂。
  2. As the SQL statement will be very dynamic, it can’t be optimized and will make indexing more difficult.

    由于SQL语句将是非常动态的,因此无法进行优化,这将使索引编制更加困难。
  3. It will create a huge overhead when communicating the SQL statement back to the db server.

    将SQL语句传递回db服务器时,将产生巨大的开销。

In these cases, PINQ may come in handy. It is a PHP version of the LINQ library which provides filtering, sorting, grouping, aggregating, and indexing on a given dataset.

在这些情况下, PINQ可能会派上用场。 它是LINQ库PHP版本ÿ

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值