惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
量子位
腾讯CDC
A
About on SuperTechFans
小众软件
小众软件
Microsoft Azure Blog
Microsoft Azure Blog
T
Tailwind CSS Blog
V
V2EX
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
GbyAI
GbyAI
Recent Announcements
Recent Announcements
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
罗磊的独立博客
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
V
Visual Studio Blog
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
有赞技术团队
有赞技术团队

Secret Weblog

Becoming More Xee: A Modern XPath and XSLT Engine in Rust Looking for new challenges! Repeat Yourself, A Bit The Curious Case of Quentell The Humble For Loop in Rust The Humble For Loop in JavaScript Don Question Best Practices I Was a 1980s Teenage Programmer Part 5: Achieving Assembly I Was a 1980s Teenage Programmer Part 4: The Call of Assembly The Tooling Shift I Was a 1980s Teenage Programmer Part 3: MSX-2 JavaScript: when you need two ways to do it! Empowering Programming Languages Bloat and Retrofuturism Refreshing my Blog Again Random Rust Impressions Apilar: An Alife System I Was a 1980s Teenage Programmer Part 2: Olivetti M24 I Was a 1980s Teenage Programmer: the Alphatronic SolidJS fits my brain Is premature optimization the root of all evil? Framework Patterns: JavaScript edition Roll Your Own Frameworks Framework Patterns Secret Weblog Highlights Refactoring to Multiple Exit Points mstform: a form library for mobx-state-tree Seven Years: A Very Personal History of the Web
extended catalog queries in Zope 3
Martijn Faassen · 2005-07-13 · via Secret Weblog

Yesterday I managed to build something in just a few hours in Zope 3 that I wouldn't have been able to build so easily in Zope 2. What I've built is an extended query system for the Zope 3 catalogs.

A sample query looks like this:

q = zapi.getUtility(interfaces.IExtendedQuery)

t1 = ('catalog', 'fulltext')
a1 = ('catalog', 'a1')

r = q.searchResults(And(Text(t1, 'foo'), InSet(a1, [1, 2]))

which, providing the given catalog indexes exist, returns all objects that have attribute a1 set to either 1 or 2, and have 'foo' in their fulltext. All kinds of nice operators exist, such as Equals, NotEquals, InRange and InSet, and you can combine them nicely using And and Or. It also ought to work over multiple catalogs.

It's not the most efficient implementation, but performance should be decent enough, and all this just took a few hours to put together and is a few pages of code. In Zope 2 this would've caused me intense headscratching and I'd certainly not be done yet.

Why was this so easy in Zope 3? I think there are two reasons:

  • clean implementation of the catalog makes its code fairly easy to read and thus write similar code. The catalog implementation in Zope 2 is a horror to try understanding, in Zope 3 it really is surprisingly easy. This pattern holds for much of the Zope 3 code base.
  • Zope 3 gives every object an integer id using the IntIds utility, which helps making the catalog so clean. IntIds rock!

The code is hidden in a customer project right now. It's easy to extract and I'll look into extracting this so other people can take a look at this in the coming weeks.