// Generate exactly one digest per wave. This includes conversational and
// non-conversational waves. The position-based API for search prevents the
// luxury of extra filtering here. Filtering can only be done in the
// searchProvider. All waves returned by the search provider must be
// included in the search result.
SearchResult result = new SearchResult(query);
if (results == null) {
return result;
}
for (WaveViewData wave : results) {
// Note: the indexing infrastructure only supports single-conversation
// waves, and requires raw wavelet access for snippeting.
ObservableWaveletData root = null;
ObservableWaveletData other = null;
ObservableWaveletData udw = null;
for (ObservableWaveletData waveletData : wave.getWavelets()) {
WaveletId waveletId = waveletData.getWaveletId();
if (IdUtil.isConversationRootWaveletId(waveletId)) {
root = waveletData;
} else if (IdUtil.isConversationalId(waveletId)) {
other = waveletData;
} else if (IdUtil.isUserDataWavelet(waveletId)) {
// assume this is the user data wavelet for the right user.
udw = waveletData;
}
}
ObservableWaveletData convWavelet = root != null ? root : other;
SupplementedWave supplement = null;
ObservableConversationView conversations = null;
if (convWavelet != null) {
OpBasedWavelet wavelet = OpBasedWavelet.createReadOnly(convWavelet);
if (WaveletBasedConversation.waveletHasConversation(wavelet)) {
conversations = conversationUtil.buildConversation(wavelet);
supplement = buildSupplement(participant, conversations, udw);
}
}
if (conversations != null) {
// This is a conversational wave. Produce a conversational digest.
result.addDigest(generateDigest(conversations, supplement, convWavelet));
} else {
// It is unknown how to present this wave.
result.addDigest(generateEmptyorUnknownDigest(wave));
}
}
assert result.getDigests().size() == results.size();
return result;
}