My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package guestbook;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.google.appengine.api.datastore.DatastoreNeedIndexException;
import com.google.appengine.api.datastore.DatastoreTimeoutException;

public class SearchJanitor {

private static final Logger log = Logger.getLogger(SearchJanitor.class.getName());

public static final int MAXIMUM_NUMBER_OF_WORDS_TO_SEARCH = 5;

public static final int MAX_NUMBER_OF_WORDS_TO_PUT_IN_INDEX = 200;

public static List<GuestBookEntry> searchGuestBookEntries(
String queryString,
PersistenceManager pm) {

StringBuffer queryBuffer = new StringBuffer();

queryBuffer.append("SELECT FROM " + GuestBookEntry.class.getName() + " WHERE ");

Set<String> queryTokens = SearchJanitorUtils
.getTokensForIndexingOrQuery(queryString,
MAXIMUM_NUMBER_OF_WORDS_TO_SEARCH);

List<String> parametersForSearch = new ArrayList<String>(queryTokens);

StringBuffer declareParametersBuffer = new StringBuffer();

int parameterCounter = 0;

while (parameterCounter < queryTokens.size()) {

queryBuffer.append("fts == param" + parameterCounter);
declareParametersBuffer.append("String param" + parameterCounter);

if (parameterCounter + 1 < queryTokens.size()) {
queryBuffer.append(" && ");
declareParametersBuffer.append(", ");

}

parameterCounter++;

}


Query query = pm.newQuery(queryBuffer.toString());

query.declareParameters(declareParametersBuffer.toString());

List<GuestBookEntry> result = null;

try {
result = (List<GuestBookEntry>) query.executeWithArray(parametersForSearch
.toArray());

} catch (DatastoreTimeoutException e) {
log.severe(e.getMessage());
log.severe("datastore timeout at: " + queryString);// + " - timestamp: " + discreteTimestamp);
} catch(DatastoreNeedIndexException e) {
log.severe(e.getMessage());
log.severe("datastore need index exception at: " + queryString);// + " - timestamp: " + discreteTimestamp);
}

return result;

}





public static void updateFTSStuffForGuestBookEntry(
GuestBookEntry guestBookEntry) {

StringBuffer sb = new StringBuffer();

sb.append(guestBookEntry.getContent());

Set<String> new_ftsTokens = SearchJanitorUtils.getTokensForIndexingOrQuery(
sb.toString(),
MAX_NUMBER_OF_WORDS_TO_PUT_IN_INDEX);


Set<String> ftsTokens = guestBookEntry.getFts();

ftsTokens.clear();

for (String token : new_ftsTokens) {
ftsTokens.add(token);

}
}

}

Change log

r23 by raphael.andre.bauer on Apr 7, 2010   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

r12 by raphael.andre.bauer on Apr 7, 2010   Diff
spelling mistake
r3 by raphael.andre.bauer on Apr 7, 2010   Diff
initial checkin
All revisions of this file

File info

Size: 2717 bytes, 104 lines

File properties

svn:mime-type
text/plain
Powered by Google Project Hosting