9
9
import net .sf .ehcache .config .Configuration ;
10
10
import net .sf .ehcache .config .SearchAttribute ;
11
11
import net .sf .ehcache .search .Attribute ;
12
+ import net .sf .ehcache .search .Direction ;
12
13
import net .sf .ehcache .search .Query ;
13
14
import net .sf .ehcache .search .Result ;
14
15
import net .sf .ehcache .search .Results ;
@@ -69,14 +70,12 @@ private void initializeCache() {
69
70
70
71
// If you want to initialize it via ehcache.xml it would look like this
71
72
// <cache name="test" maxElementsInMemory="0" eternal="true" overflowToDisk="false">
72
- // <searchAttribute name="age" expression="value.getAge()"/>
73
- // <searchAttribute name="name" class="org.sharrissf.sample.EhcacheSearchPlaying$NameAttributeExtractor"/>
74
- // <searchAttribute name="gender" expression="value.getGender()"/>
75
- // <searchAttribute name="state" expression="value.getState()"/>
73
+ // <searchAttribute name="age" expression="value.getAge()"/>
74
+ // <searchAttribute name="name" class="org.sharrissf.sample.EhcacheSearchPlaying$NameAttributeExtractor"/>
75
+ // <searchAttribute name="gender" expression="value.getGender()"/>
76
+ // <searchAttribute name="state" expression="value.getState()"/>
76
77
// </cache>
77
78
78
-
79
-
80
79
cacheManagerConfig .addCache (cacheConfig );
81
80
82
81
cacheManager = new CacheManager (cacheManagerConfig );
@@ -94,7 +93,7 @@ public void runTests() throws IOException {
94
93
Query query = cache .createQuery ();
95
94
query .includeKeys ();
96
95
query .includeValues ();
97
- query .add (new And (name .like ("Ari*" ), gender .eq (Gender .MALE )));
96
+ query .add (new And (name .like ("Ari*" ), gender .eq (Gender .MALE ))). addOrder ( age , Direction . ASCENDING ). maxResults ( 10 ) ;
98
97
99
98
long t = System .currentTimeMillis ();
100
99
System .out .println ("Searching for all Person's who's name start with Ari and are Male:" );
@@ -167,7 +166,8 @@ public static void main(String[] args) throws IOException {
167
166
public static class NameAttributeExtractor implements AttributeExtractor {
168
167
169
168
/**
170
- *
169
+ * Implementing the AttributeExtractor Interface and passing it in allows you to create very efficient and specific attribute
170
+ * extraction for performance sensative code
171
171
*/
172
172
private static final long serialVersionUID = 1L ;
173
173
0 commit comments