Skip to content

Commit

Permalink
feat: include index name
Browse files Browse the repository at this point in the history
  • Loading branch information
gilmatok committed Jun 1, 2023
1 parent dc40a24 commit 0d53785
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class DynamicSynonymTokenFilterFactory extends
});
private volatile ScheduledFuture<?> scheduledFuture;

private final IndexSettings indexSettings;
private final String location;
private final boolean expand;
private final boolean lenient;
Expand All @@ -65,6 +66,7 @@ public DynamicSynonymTokenFilterFactory(
) throws IOException {
super(name, settings);

this.indexSettings = indexSettings;
this.location = settings.get("synonyms_path");
if (this.location == null) {
throw new IllegalArgumentException(
Expand Down Expand Up @@ -163,12 +165,12 @@ SynonymFile getSynonymFile(Analyzer analyzer) {
SynonymFile synonymFile;
if (location.startsWith("http://") || location.startsWith("https://")) {
synonymFile = new RemoteSynonymFile(
environment, analyzer, expand, lenient, format, location);
this.indexSettings.getIndex().getName(), environment, analyzer, expand, lenient, format, location);
} else {
synonymFile = new LocalSynonymFile(
environment, analyzer, expand, lenient, format, location);
}
if (scheduledFuture == null) {
if (scheduledFuture == null && interval > 0) {
scheduledFuture = pool.scheduleAtFixedRate(new Monitor(synonymFile),
interval, interval, TimeUnit.SECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class RemoteSynonymFile implements SynonymFile {

private boolean lenient;

private String indexName;

private Analyzer analyzer;

private Environment env;
Expand All @@ -58,8 +60,9 @@ public class RemoteSynonymFile implements SynonymFile {

private String eTags;

RemoteSynonymFile(Environment env, Analyzer analyzer,
RemoteSynonymFile(String indexName, Environment env, Analyzer analyzer,
boolean expand, boolean lenient, String format, String location) {
this.indexName = indexName;
this.analyzer = analyzer;
this.expand = expand;
this.lenient = lenient;
Expand Down Expand Up @@ -134,7 +137,7 @@ public Reader getReader() {
.build();
CloseableHttpResponse response = null;
BufferedReader br = null;
HttpGet get = new HttpGet(location);
HttpGet get = new HttpGet(location + "?indexName=" + this.indexName);
get.setConfig(rc);
try {
response = executeHttpRequest(get);
Expand Down Expand Up @@ -191,7 +194,7 @@ public boolean isNeedReloadSynonymMap() {
.setConnectionRequestTimeout(10 * 1000)
.setConnectTimeout(10 * 1000).setSocketTimeout(15 * 1000)
.build();
HttpHead head = AccessController.doPrivileged((PrivilegedAction<HttpHead>) () -> new HttpHead(location));
HttpHead head = AccessController.doPrivileged((PrivilegedAction<HttpHead>) () -> new HttpHead(location + "?indexName=" + this.indexName));
head.setConfig(rc);

// 设置请求头
Expand Down

0 comments on commit 0d53785

Please sign in to comment.