Ejemplo n.º 1
0
size_t
UTF8StrChrFieldSearcher::matchTerms(const FieldRef & f, const size_t mintsz)
{
    (void) mintsz;
    termcount_t words(0);
    const byte * n = reinterpret_cast<const byte *> (f.data());
    const byte * e = n + f.size();
    if (f.size() >= _buf->size()) {
        _buf->reserve(f.size() + 1);
    }
    cmptype_t * fn = &(*_buf.get())[0];
    size_t fl(0);

    for( ; n < e; ) {
        if (!*n) { _zeroCount++; n++; }
        n = tokenize(n, _buf->capacity(), fn, fl);
        for(QueryTermList::iterator it=_qtl.begin(), mt=_qtl.end(); it != mt; it++) {
            QueryTerm & qt = **it;
            const cmptype_t * term;
            termsize_t tsz = qt.term(term);
            if ((tsz <= fl) && (prefix() || qt.isPrefix() || (tsz == fl))) {
                const cmptype_t *tt=term, *et=term+tsz;
                for (const cmptype_t *fnt=fn; (tt < et) && (*tt == *fnt); tt++, fnt++);
                if (tt == et) {
                    addHit(qt, words);
                }
            }
        }
        words++;
    }
    NEED_CHAR_STAT(addAnyUtf8Field(f.size()));
    return words;
}
size_t
UTF8SuffixStringFieldSearcher::matchTerms(const FieldRef & f, const size_t mintsz)
{
    (void) mintsz;
    termcount_t words = 0;
    const byte * srcbuf = reinterpret_cast<const byte *> (f.data());
    const byte * srcend = srcbuf + f.size();
    if (f.size() >= _buf->size()) {
        _buf->reserve(f.size() + 1);
    }
    cmptype_t * dstbuf = &(*_buf.get())[0];
    size_t tokenlen = 0;

    for( ; srcbuf < srcend; ) {
        if (*srcbuf == 0) {
            ++_zeroCount;
            ++srcbuf;
        }
        srcbuf = tokenize(srcbuf, _buf->capacity(), dstbuf, tokenlen);
        for (QueryTermList::iterator it = _qtl.begin(), mt = _qtl.end(); it != mt; ++it) {
            QueryTerm & qt = **it;
            const cmptype_t * term;
            termsize_t tsz = qt.term(term);
            if (matchTermSuffix(term, tsz, dstbuf, tokenlen)) {
                addHit(qt, words);
            }
        }
        words++;
    }
    return words;
}
Ejemplo n.º 3
0
bool StrChrFieldSearcher::matchDoc(const FieldRef & fieldRef)
{
  bool retval(true);
  if (_qtl.size() > 1) {
    size_t mintsz = shortestTerm();
    if (fieldRef.size() >= mintsz) {
      _words += matchTerms(fieldRef, mintsz);
    } else {
      _words += countWords(fieldRef);
    }
  } else {
    for(QueryTermList::iterator it=_qtl.begin(), mt=_qtl.end(); it != mt; it++) {
      QueryTerm & qt = **it;
      if (fieldRef.size() >= qt.termLen()) {
        _words += matchTerm(fieldRef, qt);
      } else {
        _words += countWords(fieldRef);
      }
    }
  }
  return retval;
}