This project has moved. For the latest updates, please go here.

How can I search strings with "EndsWith" condtion.

Nov 21, 2013 at 7:06 AM
I'm trying to search strings for an Unicode column with Api.MakeKey() and Api.TrySeek().

I can search "StartsWith" operation with next code.
Api.MakeKey(sess, tbl, (string)val, encode, MakeKeyGrbit.NewKey);
Api.TrySeek(sess, tbl, SeekGrbit.SeekGE);

Api.MakeKey(sess, tbl, (string)val, encode, MakeKeyGrbit.NewKey | MakeKeyGrbit.SubStrLimit);
//MakeKeyGrbit.PartialColumnEndLimit can be used insted of MakeKeyGrbit.SubStrLimit

Api.JetSetIndexRange(sess, tbl, SetIndexRangeGrbit.RangeInclusive | SetIndexRangeGrbit.RangeUpperLimit);
Is there any way to perform "EndsWith" postfix search operation?
Developer
Dec 2, 2013 at 2:47 AM
Unfortunately, there is no easy way to do it. ESE indexes things by using sorted normalized keys. Think of trying to look up all first names of 'Michael' in a typical white pages phone book. There is just no fast way to do it.

In the interest of full disclosure:
If you create a 'Tuple Index' you may be able to do it quickly. See the documentation on JET_TUPLELIMITS for some discussion.
http://msdn.microsoft.com/en-us/library/gg269207(v=exchg.10).aspx

But to be honest, it's not well-tested, and creates a lot of disk overhead in order to pre-create the index entries. If you try it out, prepare to be disappointed. I don't recommend it.

-martin