github-actions[bot] commented on code in PR #70265:
URL: https://github.com/apache/doris/pull/70265#discussion_r4637500457


##########
be/src/storage/index/inverted/analysis/tokenizer/standard/uax29_tokenizer.cpp:
##########
@@ -0,0 +1,125 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "storage/index/inverted/analysis/tokenizer/standard/uax29_tokenizer.h"
+
+#include <algorithm>
+#include <array>
+#include <cstdint>
+
+#include "common/logging.h"
+#include "storage/index/inverted/analysis/scratch.h"
+#include "storage/index/inverted/analysis/token_batch.h"
+#include "storage/index/inverted/analysis/tokenizer/byte_classifier.h"
+#include "storage/index/inverted/analysis/tokenizer/standard/uax29_table.h"
+#include "storage/index/inverted/analysis/tokenizer/utf8_validator.h"
+#include "util/utf8_check.h"
+
+namespace doris::segment_v2::inverted_index {
+
+namespace {
+
+constexpr std::array<std::string_view, 33> STOP_WORDS = {
+        "a",   "an",    "and",  "are",   "as",    "at",   "be",   "but", "by", 
 "for",  "if",
+        "in",  "into",  "is",   "it",    "no",    "not",  "of",   "on",  "or", 
 "such", "that",
+        "the", "their", "then", "there", "these", "they", "this", "to",  
"was", "will", "with"};
+constexpr size_t LONGEST_STOP_WORD = 5;
+
+// A term of at most 7 bytes as one integer: its bytes from the low end and 
its length in the top
+// byte, so that terms of different lengths never compare equal.
+constexpr uint64_t pack_term(std::string_view term) {
+    uint64_t key = static_cast<uint64_t>(term.size()) << 56;
+    for (size_t i = 0; i < term.size(); ++i) {
+        key |= static_cast<uint64_t>(static_cast<uint8_t>(term[i])) << (8 * i);
+    }
+    return key;
+}
+
+// Sorted for binary search; most tokens leave on the length test before it.
+constexpr std::array<uint64_t, STOP_WORDS.size()> STOP_WORD_KEYS = [] {
+    std::array<uint64_t, STOP_WORDS.size()> keys {};
+    for (size_t i = 0; i < STOP_WORDS.size(); ++i) {
+        keys[i] = pack_term(STOP_WORDS[i]);
+    }
+    std::ranges::sort(keys);
+    return keys;
+}();
+
+} // namespace
+
+std::span<const std::string_view> standard_stop_words() {
+    return STOP_WORDS;
+}
+
+bool is_standard_stop_word(std::string_view term) {
+    return term.size() <= LONGEST_STOP_WORD &&
+           std::ranges::binary_search(STOP_WORD_KEYS, pack_term(term));
+}
+
+Uax29Tokenizer::Uax29Tokenizer(bool lowercase, bool stop_words)
+        : _table(Uax29Table::instance()), _lowercase(lowercase), 
_stop_words(stop_words) {}
+
+void Uax29Tokenizer::reset(std::string_view text) {
+    _pos = 0;
+    // Strict UTF-8 passing decides alone; the lenient rule decides the rest, 
the overlong forms.
+    if (!doris::validate_utf8(text.data(), text.size()) && 
!lenient_utf8_valid(text)) {

Review Comment:
   [P2] Release the lowered scratch on invalid resets. When a lowercasing 
stream processes a large valid value, `_lowered` grows to that row's size. If 
the next value is invalid UTF-8, this early return leaves `_lowered` untouched 
because `release_oversized_scratch()` is below the branch, so 
`reserved_bytes()` keeps the row-sized allocation across subsequent rows and 
violates the `TextTokenStream::reset` high-water contract. Apply the same 
scratch release before returning for invalid input.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to