Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
import reactor.core.publisher.Mono;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -169,6 +173,14 @@ public static synchronized String formatCoordinate(double coordinate) {
return COORDINATE_FORMATTER.format(coordinate);
}

public static String readSynonymsFromFile(Path filePath) {
try {
return new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8);
} catch (IOException ex) {
throw new ClientLogger(Utility.class).logExceptionAsError(new UncheckedIOException(ex));
}
}

private Utility() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,17 @@ public SynonymMap setETag(String eTag) {
this.eTag = eTag;
return this;
}

/**
* Creates a new instance of SynonymMap with synonyms read from the passed file.
*
* @param name The name of the synonym map.
* @param filePath The path to the file where the formatted synonyms are read.
* @return A SynonymMap.
* @throws java.io.UncheckedIOException If reading {@code filePath} fails.
*/
public static SynonymMap createFromFile(String name, java.nio.file.Path filePath) {
String synonyms = com.azure.search.documents.implementation.util.Utility.readSynonymsFromFile(filePath);
return new SynonymMap(name, synonyms);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@ private void customizeSynonymMap(ClassCustomization classCustomization) {
.setDescription("Constructor of {@link SynonymMap}.")
.setParam("name", "The name of the synonym map.")
.setParam("synonyms", "A series of synonym rules in the specified synonym map format. The rules must be separated by newlines.");

classCustomization.addMethod(joinWithNewline(
"/**",
" * Creates a new instance of SynonymMap with synonyms read from the passed file.",
" *",
" * @param name The name of the synonym map.",
" * @param filePath The path to the file where the formatted synonyms are read.",
" * @return A SynonymMap.",
" * @throws java.io.UncheckedIOException If reading {@code filePath} fails.",
" */",
"public static SynonymMap createFromFile(String name, java.nio.file.Path filePath) {",
" String synonyms = com.azure.search.documents.implementation.util.Utility.readSynonymsFromFile(filePath);",
" return new SynonymMap(name, synonyms);",
"}"));
}

private void customizeSearchResourceEncryptionKey(ClassCustomization keyCustomization,
Expand Down