msfroh commented on code in PR #13054: URL: https://github.com/apache/lucene/pull/13054#discussion_r1700987077
########## 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 { Review Comment: For now, since I split the synonyms across three files (`synonyms.mdt`, `synonyms.wrd`, and `synonyms.fst`), I assumed that there would be a single synonym map per directory. That said, I suppose it wouldn't be hard to combine those three into a single file (with a `.syn` extension, say), where the `SynonymMapDirectory` could look at a prefix. Specifically, the current implementation reads the metadata and words once (keeping the words on-heap), then spends the rest of its time in the FST. Then a single filesystem directory could have something like: ``` first_synonyms.syn second_synonyms.syn ... etc. ... ``` What do you think? (I'm also happy to let each serialized `SynonymMap` live in its own directory.) -- 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