deemoliu commented on code in PR #16364:
URL: https://github.com/apache/pinot/pull/16364#discussion_r2345321254


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/realtime/impl/invertedindex/RealtimeNgramFilteringIndex.java:
##########
@@ -0,0 +1,191 @@
+/**
+ * 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.
+ */
+package org.apache.pinot.segment.local.realtime.impl.invertedindex;
+
+import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import org.apache.lucene.analysis.ngram.NGramTokenizer;
+import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
+import org.apache.pinot.segment.spi.index.mutable.MutableTextIndex;
+import org.roaringbitmap.buffer.ImmutableRoaringBitmap;
+import org.roaringbitmap.buffer.MutableRoaringBitmap;
+
+
+/**
+ * RealtimeNgramFilteringIndex is a mutable inverted index that supports 
adding document IDs for n-grams. An n-gram
+ * is a contiguous sequence of n characters from input text. The length of the 
n-gram is variable between
+ * [minNgramLength, maxNgramLength] as specified in the index config. 
Internally, it uses a realtime inverted index
+ * which maps n-grams to their posting lists (document IDs). The index is 
thread-safe for single writer and multiple
+ * readers.
+ */
+public class RealtimeNgramFilteringIndex implements MutableTextIndex {
+  private final String _column;
+  // Under the hood, ngram index is implemented as an inverted index from 
n-grams to their posting lists.
+  private final RealtimeInvertedIndex _invertedIndex;
+  // A mapping from n-grams to their dictionary IDs.
+  private final Object2IntOpenHashMap<String> _ngramToDictIdMapping;
+  // Read and write locks for thread safety.
+  private final ReentrantReadWriteLock.ReadLock _readLock;
+  private final ReentrantReadWriteLock.WriteLock _writeLock;
+
+  // Next document ID to be assigned.
+  private int _nextDocId = 0;
+  private int _nextDictId = 0;
+
+  private final int _minNgramLength;
+  private final int _maxNgramLength;
+
+  public RealtimeNgramFilteringIndex(String column, int minNgramLength, int 
maxNgramLength) {
+    _column = column;
+    _invertedIndex = new RealtimeInvertedIndex();
+    _ngramToDictIdMapping = new Object2IntOpenHashMap<>();

Review Comment:
   shall we handle not existing keys with default value?
   _ngramToDictIdMapping.defaultReturnValue(-1);



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to