msfroh commented on code in PR #13054:
URL: https://github.com/apache/lucene/pull/13054#discussion_r1701014637


##########
lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/SynonymMapDirectory.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.lucene.analysis.synonym;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.List;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.fst.ByteSequenceOutputs;
+import org.apache.lucene.util.fst.FST;
+import org.apache.lucene.util.fst.OffHeapFSTStore;
+
+/**
+ * Wraps an {@link FSDirectory} to read and write a compiled {@link 
SynonymMap}. When reading, the
+ * FST and output words are kept off-heap.
+ */
+public class SynonymMapDirectory implements Closeable {
+  private final SynonymMapFormat synonymMapFormat =
+      new SynonymMapFormat(); // TODO -- Should this be more 
flexible/codec-like? Less?
+  private final Directory directory;
+
+  public SynonymMapDirectory(Path path) throws IOException {
+    directory = FSDirectory.open(path);
+  }
+
+  public IndexOutput fstOutput() throws IOException {
+    return synonymMapFormat.getFSTOutput(directory);
+  }
+
+  public WordsOutput wordsOutput() throws IOException {
+    return synonymMapFormat.getWordsOutput(directory);
+  }
+
+  public void writeMetadata(
+      int wordCount, int maxHorizontalContext, FST.FSTMetadata<BytesRef> 
fstMetadata)
+      throws IOException {
+    synonymMapFormat.writeMetadata(directory, wordCount, maxHorizontalContext, 
fstMetadata);
+  }
+
+  public SynonymMap readMap() throws IOException {
+    return synonymMapFormat.readSynonymMap(directory);

Review Comment:
   I think I like a model where the user creates a `SynonymMapDirectory` and 
passes it to `SynonymMap.Builder.build())` if they want to store/read compiled 
synonyms on the filesystem.
   
   Before returning the `IndexInput`, the `SynonymMapDirectory` will keep a 
reference to it. When the user calls `close` on their `SynonymMapDirectory`, it 
will close the outstanding `IndexInput`.



-- 
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: issues-unsubscr...@lucene.apache.org

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


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

Reply via email to