| Author |
Message |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 29/07/2010 06:52:16
|
hajmoh
Joined: 29/07/2010 06:45:36
Messages: 3
Offline
|
Hello,
i create index for many attributes and i want to get a list which satisfies more than 1 constraints.
Below how we can get list satisfying one constraint.
my question is how we can use multi elements ?, not just one as i did above _multiMap.get(new Key(queueId)) and what we can find on phonebook example.
thanks for responses.
This message was edited 1 time. Last update was at 29/07/2010 08:18:26
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 29/07/2010 10:31:31
|
saoj
Joined: 05/09/2008 13:26:12
Messages: 46
Offline
|
Not sure I followed it, can you rephrase?
|
-Sergio Oliveira Junior |
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 29/07/2010 10:47:47
|
hajmoh
Joined: 29/07/2010 06:45:36
Messages: 3
Offline
|
above we create an index for the attributes "queueId", "shippingDone", "timeNextSend".
if i want to research a list that satisfy the constraints queueId = 1, shippingDone = 3 and timeNextSend = 3000.
i find a way just to get a list satisfying juste one constraint ( look the seconde code)
How can i do it??
thank you
This message was edited 1 time. Last update was at 29/07/2010 10:48:08
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 31/07/2010 16:42:42
|
saoj
Joined: 05/09/2008 13:26:12
Messages: 46
Offline
|
Ok. When you are using a compound index, Space4J needs to know how to compare the index's key, which is of course a compound key.
It does come with a default way of comparing compound keys: the KeyComparator. It compares Strings, Dates and Numbers like you would expect.
If you want to change the default comparator, because you have some complex objects in the compound key, you have to implement you own comparator and pass to the Index when you create it.
It does not look like you need your own comparator. If you want to get a list that satisfy queueId = 1, shippingDone = 3 and timeNextSend = 3000 it is very easy:
1) Your index should be a MULTI index, because it is not UNIQUE, meaning you will have more than one record per queueId, shippingDone and timeNextSend.
2) It can be sorted or non-sorted, depending if you want to fetch RANGES or if you want to fetch SORTED results.
3) After creating your index, all you have to do is:
If your index is sorted (MULTI_SORTED), you can fetch ranges:
Refer to here to sort from SortedMaps in Java:
http://download.oracle.com/javase/1.4.2/docs/api/java/util/SortedMap.html
Plus I also recommend you to download and check the Space4J sources if you want to have a better understanding of its internals.
Let me know if it worked for you. Also please share with us what kind of system you are developing with Space4J.
This message was edited 3 times. Last update was at 31/07/2010 16:46:11
|
-Sergio Oliveira Junior |
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 04/08/2010 03:25:37
|
hajmoh
Joined: 29/07/2010 06:45:36
Messages: 3
Offline
|
Thank you very much.
I'll test your recommandation and i'll infrom you about results.
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 18/09/2010 15:48:14
|
saoj
Joined: 05/09/2008 13:26:12
Messages: 46
Offline
|
There were some improvements with Space4J 0.9.2 in the MULTI indexes (sorted and non-sorted).
Please refer to: http://s4j.mentaframework.org/posts/list/24.page
|
-Sergio Oliveira Junior |
|
|
 |
|
|
|
|