msfroh commented on code in PR #13054: URL: https://github.com/apache/lucene/pull/13054#discussion_r1700999887
########## lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/SynonymMap.java: ########## @@ -291,11 +306,35 @@ public SynonymMap build() throws IOException { fstCompiler.add(Util.toUTF32(input, scratchIntsRef), scratch.toBytesRef()); } - FST<BytesRef> fst = FST.fromFSTReader(fstCompiler.compile(), fstCompiler.getFSTReader()); - return new SynonymMap(fst, words, maxHorizontalContext); + FST.FSTMetadata<BytesRef> fstMetaData = fstCompiler.compile(); + if (directory != null) { + fstOutput.close(); // TODO -- Should fstCompiler.compile take care of this? + try (SynonymMapDirectory.WordsOutput wordsOutput = directory.wordsOutput()) { + BytesRef scratchRef = new BytesRef(); + for (int i = 0; i < words.size(); i++) { + words.get(i, scratchRef); + wordsOutput.addWord(scratchRef); + } + } + directory.writeMetadata(words.size(), maxHorizontalContext, fstMetaData); + return directory.readMap(); + } + FST<BytesRef> fst = FST.fromFSTReader(fstMetaData, fstCompiler.getFSTReader()); + BytesRefHashLike wordsLike = + new BytesRefHashLike() { + @Override + public void get(int id, BytesRef scratch) { + words.get(id, scratch); + } + }; + return new SynonymMap(fst, wordsLike, maxHorizontalContext); } } + abstract static class BytesRefHashLike { Review Comment: Hmm... you're right. More importantly, since the ctor for `SynonymMap` is public, I probably shouldn't change its signature. I'll leave the existing public constructor (that takes a `BytesRefHash`), add a new private constructor (that takes a `SynonymDictionary` -- the new name I picked for `BytesRefHashLike`), and have the public constructor delegate to the private one. (That way, `SynonymDictionary` can remain package-private.) -- 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