List Info

Thread: Searching magma string indices




Searching magma string indices
country flaguser name
South Africa
2007-02-28 17:13:24
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





_______________________________________________
Magma mailing list
Magmalists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/magma


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )