I’m currently working on the latest version of our Business Directory product for Business Link Kent (it should be going live on 8th Feb, in fact).
Because of the complex searching requirements plain old ZCTextIndex or TextIndex just aren’t enough, and we’ve incorporated the very powerful TextIndexNG3 instead.
Unfortunately the installation documentation and so on doesn’t really deal with implementing new indexes using the product. Nor does it show how to programatically convert the pre-existing indexes upon installation of your product; instead it is described as manual steps.
Manual steps do not play nice with either our automated testing strategy or the fact that we blow away and rebuild our development environments 3 or 4 times a day.
Install.py (yes, this is a Plone 2.1 site and no, I’m not using Generic Setup for this one) put the following function (I’m using stemming here, so don’t copy this blindly if you don’t want the effects of stemming):
updateIndexes(out) from your
install method and lo! your indexes are converted by your install script, rather than having to do it manually each time.
To implement new TextIndexNG3 indexes from within your Archetypes schema definition is very simple. I’m still debating whether I should be making use of the broader ability of TextIndexNG3 to search across a subset of the fields that it indexes (meaning that I might not need to create multiple TextIndexNG3 indexes), but for right now I’m going the simple route and defining them on the schema as I would for any other type of index.
Once you’ve installed TextIndexNG3 have a look at
Products/TextIndexNG3/src/config.py. In there are all the parameters that you can pass at the point of index creation. To do this in Archetypes it’s exactly the same as it would be for any other index; any non-default creation parameters should be comma separated after the index type is specified. For example:
So far the product looks very powerful, and it’s definitely sorted all my complex searching requirements (ranges, booleans and so forth) that until now had me completely stumped.