Drupal 6 和视图 2 - 不同字段
我正在使用 Feeds 模块导入大量 Feed Item 节点。由于 Feed 文件格式错误,我收到了大量重复项。我使用视图来显示这些节点,并且需要能够在“节点:发布日期”字段上添加 DISTINCT 过滤器,因此每个发布日期我只获得 1 个结果。
可以说,我还将研究从源头解决问题(我不想首先拥有所有这些重复项),但这本身就是一个有趣的问题 - 我找不到添加对节点 ID 以外的字段(在视图的基本设置框中有自己的选项)进行 DISTINCT 过滤。
I'm using the Feeds module to import lots of Feed Item nodes. Due to a malformed feed file, I'm getting lots of duplicates. I'm using a View to display these nodes, and need to be able to add a DISTINCT filter on the "Node: Post Date" field, so I only get 1 result for each post-date.
I will also look into tackling the problem at the source so to speak (I don't want to have all those duplicates in the first place), but this is an interesting issue in itself - I can't find a way to add a DISTINCT filter on a field other than the Node ID (which has it's own option in the View's Basic Settings box).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我发现了一篇很棒的文章,介绍了在执行视图之前更改从视图生成的 SQL 查询的好方法:http://echodittolabs.org/blog/2010/06/group-views。我用它基本上将 GROUP BY 子句后缀到查询的末尾(以一种非常好的、干净的和通用的方式)。
顺便说一句,我还找到了一种方法来解决导入大量重复提要项目的问题,其详细信息如下:http://drupal.org/node/661314#comment-3667228。它采用了相当极端的方法(在每次更新之前删除所有项目),但这是某些令人讨厌的格式错误的提要的唯一解决方案。
我一直在等待 Views 的一些未被发现的功能可以让你做到这一点,但我认为没有 - 也许在下一个版本中;)
I found a great article on a good way to alter the SQL queries that are generated from views before they get executed: http://echodittolabs.org/blog/2010/06/group-views. I used this to basically suffix a GROUP BY clause to the end of the query (in a really nice, clean and versatile way).
As an aside, I also found a way to tackle the issue of importing lots of duplicate feed items, the details of which are here: http://drupal.org/node/661314#comment-3667228. It adopts quite an extreme approach (deleting all items before each update), but this is the only solution for some nasty malformed feeds.
I was holding out for some undiscovered feature of Views that let you do this, but I don't think there is one - maybe in the next version ;)
有两个选项可以解决此问题:\
应用此补丁
或
hook_views_query_alter =>只需粘贴
$query->distinct = 1;
$query->no_distinct = 'views_groupby';
There are two option to solve this:\
apply this patch
OR
hook_views_query_alter => just paste
$query->distinct = 1;
$query->no_distinct = 'views_groupby';
我想你有两个选择:要么在视图模板文件中添加一些逻辑来跳过重复的项目,要么实现
hook_views_query_alter()
更改视图使用的查询,添加DISTINCT
子句。I guess you have two options: either put some logic in the view template file to skip the duplicate items or implement
hook_views_query_alter()
to change the query used by the view, adding theDISTINCT
clause.我们在 drupal 6.x 视图中发现了这个问题 - 150 个项目中有 7 个重复了一两次。不知道为什么。仅匿名用户出现问题。幸运的是,视图 6.x.2.16 在基本设置下提供了“独特”设置,我将其设置为“是”并删除了重复项。
We found this issue in drupal 6.x view - had 7 of 150 items duplicated one or twice. No idea why. Issue only appeared for anonymous users. Luckily, views 6.x.2.16 provides a 'distinct' setting under the basic settings, I set it to Yes and got rid of the duplicates.