Searching magma string indices

Brent Pinkney brent at zamail.co.za
Wed Feb 28 23:13:24 UTC 2007


Hi,

I have been thinking about how one could search Magma String indices for a given prefix or suffix. i.e. find all words starting with 'foo' or ending with 'bar'.


One can add SQL-ish "like" functionality for a prefix seach quite easily with the method:

	MaClause >> #like: aString
		"aString is a SQL-ish term and may include a trailing %"

		self from: aString upTo: (aString copyWithout: $%) maAlphabeticalNext
	!

For example: find all the people whose name starts with 'Jo':

	self people where: [ :p | p familyName like: 'Jo%' ].


This executes as a very efficient indixed search and will be debuting (in some form) in the next release of Lava.


However, finding all the strings ending with 'bar' is more troublesome as there is no way to map this to a #from:to:# expression on the Magma index.


UNLESS of course, we maintain another, hidden, String index on the collection with the hash of the string reversed.
That is

	self people where: [ :p | p familyName like '%Jo' ].

becomes:
	self people read: #familyName_reversed from: 'oJ' to: ...


It is very late here, so I have not been able to try it out, but I welcome comments.

What would be really nice is an index on expressions of the form '%foo%bar%'. Somehow I doubt this.



Cheers

Brent







More information about the Magma mailing list