Pinned topic How to fetch data from cache by partial key
I would like to retrieve from cache all keys which have specific prefix.
In SQL my requirement looks like:
select c.id from Cell c where c.id like '123as%';
I am trying to define dynamic indexes and using functions:
1) findRange of MapRangeIndex with right padding of highAttributeValue to total length of 40 characters
2) findGreater of MapRangeIndex with additional manipulations performing on result set
I am looking for more simple and efficient way to implement current requirement.
Have you any idea?
(I am using WXS 18.104.22.168)
jhanders 1200009V3S266 Posts
Re: How to fetch data from cache by partial key2013-06-10T11:25:39ZThis is the accepted answer. This is the accepted answer.
eXtreme Scale does not currently have a like mechanism for index. The query language for eXtreme Scale (based off of the JPA query language) allows for like operations. That would be the usual way to do a like. The issue is though that eXtreme Scale needs iterate over all the keys to determine if it matches the like.
The other way this is solved is by creating a reverse index where you end up storing the characters you care about in a separate map and look up the characters to determine which keys you need. This is helpful for a type ahead cache for instance.
So for a key of 123as, you would put 1, 2, 3, a, s, 12, 23, 3a, as, 123, 23a, 3as, 123a, 23as, and 123as all as keys into the map each pointing to to a set that had 123as in it. If you only cared about the beginning characters as a prefix you could just do those substrings (1, 12, 123, 123a, and 123as). And the simplest being is you have a set prefix length of say three characters you would only need to include 123 in your reverse index map.
With this reverse index map now you can do the index operations you mentioned earlier. You can do indexes that give you all prefixes that start are within a specific range you are looking for.
I hope this helps give some direction.