- char ch[3] = {
- char(trgm & 0xff), char((trgm >> 8) & 0xff), char((trgm >> 16) & 0xff)
- };
-
- string str = "'";
- for (unsigned i = 0; i < 3;) {
- if (ch[i] == '\\') {
- str.push_back('\\');
- str.push_back(ch[i]);
- ++i;
- } else if (int(ch[i]) >= 32 && int(ch[i]) <= 127) { // Holds no matter whether char is signed or unsigned.
- str.push_back(ch[i]);
- ++i;
- } else {
- // See if we have an entire UTF-8 codepoint, and that it's reasonably printable.
- mbtowc(nullptr, 0, 0);
- wchar_t pwc;
- int ret = mbtowc(&pwc, ch + i, 3 - i);
- if (ret >= 1 && pwc >= 32) {
- str.append(ch + i, ret);
- i += ret;
+ if (td->docids.empty()) {
+ td->docids = move(decoded);
+ } else {
+ tmp->clear();
+ set_union(decoded.begin(), decoded.end(), td->docids.begin(), td->docids.end(), back_inserter(*tmp));
+ swap(*tmp, td->docids);
+ }
+ if (--td->remaining_trigrams_to_read > 0) {
+ // Need to wait for more.
+ if (ignore_case) {
+ dprintf(" ... %u reads left in OR group %u (%zu docids in list)\n",
+ td->remaining_trigrams_to_read, td->index, td->docids.size());
+ }
+ return false;
+ }
+ if (cur_candidates->empty()) {
+ if (ignore_case) {
+ dprintf(" ... all reads done for OR group %u (%zu docids)\n",
+ td->index, td->docids.size());
+ }
+ *cur_candidates = move(td->docids);
+ } else {
+ tmp->clear();
+ set_intersection(cur_candidates->begin(), cur_candidates->end(),
+ td->docids.begin(), td->docids.end(),
+ back_inserter(*tmp));
+ swap(*cur_candidates, *tmp);
+ if (ignore_case) {
+ if (cur_candidates->empty()) {
+ dprintf(" ... all reads done for OR group %u (%zu docids), intersected (none left, search is done)\n",
+ td->index, td->docids.size());
+ return true;