bool WildcardTermEnum::termCompare(const TermPtr& term) { if (field == term->field()) { String searchText(term->text()); if (boost::starts_with(searchText, pre)) { return wildcardEquals(text, 0, searchText, preLen); } } _endEnum = true; return false; }
bool WildcardTermEnum::termCompare(Term* term) { if ( term!=NULL && __term->field() == term->field() ) { const TCHAR* searchText = term->text(); const TCHAR* patternText = __term->text(); if ( _tcsncmp( searchText, pre, preLen ) == 0 ){ return wildcardEquals(patternText+preLen, __term->textLength()-preLen, 0, searchText, term->textLength(), preLen); } } _endEnum = true; return false; }
bool WildcardTermEnum::wildcardEquals(const String& pattern, int32_t patternIdx, const String& string, int32_t stringIdx) { int32_t p = patternIdx; for (int32_t s = stringIdx; ; ++p, ++s) { // End of string yet? bool sEnd = (s >= (int32_t)string.length()); // End of pattern yet? bool pEnd = (p >= (int32_t)pattern.length()); // If we're looking at the end of the string if (sEnd) { // Assume the only thing left on the pattern is/are wildcards bool justWildcardsLeft = true; // Current wildcard position int32_t wildcardSearchPos = p; // While we haven't found the end of the pattern, and haven't encountered any non-wildcard characters while (wildcardSearchPos < (int32_t)pattern.length() && justWildcardsLeft) { // Check the character at the current position wchar_t wildchar = pattern[wildcardSearchPos]; // If it's not a wildcard character, then there is more pattern information after this/these wildcards. if (wildchar != WILDCARD_CHAR && wildchar != WILDCARD_STRING) { justWildcardsLeft = false; } else { // to prevent "cat" matches "ca??" if (wildchar == WILDCARD_CHAR) { return false; } // Look at the next character ++wildcardSearchPos; } } // This was a prefix wildcard search, and we've matched, so return true. if (justWildcardsLeft) { return true; } } // If we've gone past the end of the string, or the pattern, return false. if (sEnd || pEnd) { break; } // Match a single character, so continue. if (pattern[p] == WILDCARD_CHAR) { continue; } if (pattern[p] == WILDCARD_STRING) { // Look at the character beyond the '*' characters. while (p < (int32_t)pattern.length() && pattern[p] == WILDCARD_STRING) { ++p; } // Examine the string, starting at the last character. for (int32_t i = string.length(); i >= s; --i) { if (wildcardEquals(pattern, p, string, i)) { return true; } } break; } if (pattern[p] != string[s]) { break; } } return false; }
bool WildcardTermEnum::wildcardEquals(const TCHAR* pattern, int32_t patternLen, int32_t patternIdx, const TCHAR* str, int32_t strLen, int32_t stringIdx) { for (int32_t p = patternIdx; ; ++p) { for (int32_t s = stringIdx; ; ++p, ++s) { // End of str yet? bool sEnd = (s >= strLen); // End of pattern yet? bool pEnd = (p >= patternLen); // If we're looking at the end of the str... if (sEnd) { // Assume the only thing left on the pattern is/are wildcards bool justWildcardsLeft = true; // Current wildcard position int32_t wildcardSearchPos = p; // While we haven't found the end of the pattern, // and haven't encountered any non-wildcard characters while (wildcardSearchPos < patternLen && justWildcardsLeft) { // Check the character at the current position TCHAR wildchar = pattern[wildcardSearchPos]; // If it's not a wildcard character, then there is more // pattern information after this/these wildcards. if (wildchar != LUCENE_WILDCARDTERMENUM_WILDCARD_CHAR && wildchar != LUCENE_WILDCARDTERMENUM_WILDCARD_STRING){ justWildcardsLeft = false; }else{ // to prevent "cat" matches "ca??" if (wildchar == LUCENE_WILDCARDTERMENUM_WILDCARD_CHAR) return false; wildcardSearchPos++; // Look at the next character } } // This was a prefix wildcard search, and we've matched, so // return true. if (justWildcardsLeft) return true; } // If we've gone past the end of the str, or the pattern, // return false. if (sEnd || pEnd) break; // Match a single character, so continue. if (pattern[p] == LUCENE_WILDCARDTERMENUM_WILDCARD_CHAR) continue; if (pattern[p] == LUCENE_WILDCARDTERMENUM_WILDCARD_STRING) { // Look at the character beyond the '*'. ++p; // Examine the str, starting at the last character. for (int32_t i = strLen; i >= s; --i) { if (wildcardEquals(pattern, patternLen, p, str, strLen, i)) return true; } break; } if (pattern[p] != str[s]) break; } return false; } }