Skip to content

Commit

Permalink
Refactor code: Replace redundant conditions and enhance readability a…
Browse files Browse the repository at this point in the history
…cross several classes.
  • Loading branch information
marevol committed Oct 12, 2024
1 parent 5fdce1d commit e166c7e
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 46 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/codelibs/fess/suggest/Suggester.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ public Suggester(final Client client, final SuggestSettings settings, final Read
final ReadingConverter contentsReadingConverter, final Normalizer normalizer, final SuggestAnalyzer analyzer,
final ExecutorService threadPool) {
this.client = client;
this.suggestSettings = settings;
suggestSettings = settings;
this.readingConverter = readingConverter;
this.contentsReadingConverter = contentsReadingConverter;
this.normalizer = normalizer;
this.analyzer = analyzer;
this.index = settings.getAsString(SuggestSettings.DefaultKeys.INDEX, StringUtil.EMPTY);
index = settings.getAsString(SuggestSettings.DefaultKeys.INDEX, StringUtil.EMPTY);
this.threadPool = threadPool;

if (logger.isDebugEnabled()) {
logger.debug("Create suggester instance for {}", this.index);
logger.debug("Create suggester instance for {}", index);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/codelibs/fess/suggest/SuggesterBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public class SuggesterBuilder {

public SuggesterBuilder settings(final SuggestSettings settings) {
this.settings = settings;
this.settingsBuilder = null;
settingsBuilder = null;
return this;
}

public SuggesterBuilder settings(final SuggestSettingsBuilder settingsBuilder) {
this.settingsBuilder = settingsBuilder;
this.settings = null;
settings = null;
return this;
}

Expand All @@ -57,8 +57,8 @@ public SuggesterBuilder readingConverter(final ReadingConverter readingConverter
return this;
}

public SuggesterBuilder contentsReadigConverter(final ReadingConverter contentsReadigConverter) {
this.contentsReadingConverter = contentsReadigConverter;
public SuggesterBuilder contentsReadigConverter(final ReadingConverter contentsReadingConverter) {
this.contentsReadingConverter = contentsReadingConverter;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class AnalyzerConverter implements ReadingConverter {
public AnalyzerConverter(final Client client, final SuggestSettings settings) {
this.client = client;
this.settings = settings;
this.analyzerSettings = settings.analyzer();
analyzerSettings = settings.analyzer();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ public SuggestItem(final String[] text, final String[][] readings, final String[

this.languages = languages != null ? languages : new String[] {};

this.kinds = new Kind[] { kind };
kinds = new Kind[] { kind };
if (userBoost > 1) {
this.userBoost = userBoost;
} else {
this.userBoost = 1;
}
this.docFreq = docFreq;
this.queryFreq = queryFreq;
this.timestamp = ZonedDateTime.now();
this.emptySource = createEmptyMap();
this.id = SuggestUtil.createSuggestTextId(this.text);
timestamp = ZonedDateTime.now();
emptySource = createEmptyMap();
id = SuggestUtil.createSuggestTextId(this.text);
}

public String getText() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,20 @@ public SuggestIndexer(final Client client, final String index, final ReadingConv
this.client = client;
this.index = index;

this.supportedFields = settings.array().get(SuggestSettings.DefaultKeys.SUPPORTED_FIELDS);
this.badWords = settings.badword().get(true);
this.tagFieldNames = settings.getAsString(SuggestSettings.DefaultKeys.TAG_FIELD_NAME, StringUtil.EMPTY).split(",");
this.roleFieldName = settings.getAsString(SuggestSettings.DefaultKeys.ROLE_FIELD_NAME, StringUtil.EMPTY);
this.langFieldName = settings.getAsString(SuggestSettings.DefaultKeys.LANG_FIELD_NAME, StringUtil.EMPTY);
this.parallel = settings.getAsBoolean(SuggestSettings.DefaultKeys.PARALLEL_PROCESSING, false);
supportedFields = settings.array().get(SuggestSettings.DefaultKeys.SUPPORTED_FIELDS);
badWords = settings.badword().get(true);
tagFieldNames = settings.getAsString(SuggestSettings.DefaultKeys.TAG_FIELD_NAME, StringUtil.EMPTY).split(",");
roleFieldName = settings.getAsString(SuggestSettings.DefaultKeys.ROLE_FIELD_NAME, StringUtil.EMPTY);
langFieldName = settings.getAsString(SuggestSettings.DefaultKeys.LANG_FIELD_NAME, StringUtil.EMPTY);
parallel = settings.getAsBoolean(SuggestSettings.DefaultKeys.PARALLEL_PROCESSING, false);
this.readingConverter = readingConverter;
this.contentsReadingConverter = contentsReadingConverter;
this.normalizer = normalizer;
this.analyzer = analyzer;
this.settings = settings;

this.contentsParser = new DefaultContentsParser();
this.suggestWriter = new SuggestIndexWriter();
contentsParser = new DefaultContentsParser();
suggestWriter = new SuggestIndexWriter();

this.threadPool = threadPool;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public ESSourceReader(final Client client, final SuggestSettings settings, final
this.client = client;
this.settings = settings;
this.indexName = indexName;
this.supportedFields = settings.array().get(SuggestSettings.DefaultKeys.SUPPORTED_FIELDS);
this.totalDocNum = getTotal();
supportedFields = settings.array().get(SuggestSettings.DefaultKeys.SUPPORTED_FIELDS);
totalDocNum = getTotal();
}

@Override
Expand Down Expand Up @@ -100,7 +100,7 @@ public void setQuery(final QueryBuilder queryBuilder) {
}

public void addSort(final SortBuilder<?> sortBuilder) {
this.sortList.add(sortBuilder);
sortList.add(sortBuilder);
}

public void setLimitDocNumPercentage(final String limitPercentage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class QueryLog {
private final String fq;

public QueryLog(final String queryString, @Nullable final String filterQueryString) {
this.q = queryString;
this.fq = filterQueryString;
q = queryString;
fq = filterQueryString;
}

public String getQueryString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class AnalyzerNormalizer implements Normalizer {
public AnalyzerNormalizer(final Client client, final SuggestSettings settings) {
this.client = client;
this.settings = settings;
this.analyzerSettings = settings.analyzer();
analyzerSettings = settings.analyzer();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static char mergeChar(final char c1, final char c2) {
break;
}
}
} else if ((c2 == '゚') && ("ハヒフヘホ".indexOf(c1) >= 0)) {
} else if (c2 == '゚' && "ハヒフヘホ".indexOf(c1) >= 0) {
switch (c1) {
case 'ハ':
return 'パ';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,27 @@ public void setWindowSize(final int windowSize) {
}

public void addTag(final String tag) {
this.tags.add(tag);
tags.add(tag);
}

public void addRole(final String role) {
this.roles.add(role);
roles.add(role);
}

public void addField(final String field) {
this.fields.add(field);
fields.add(field);
}

public void addLanguage(final String lang) {
this.languages.add(lang);
languages.add(lang);
}

public void setDetail(final boolean detail) {
this.detail = detail;
}

public void addExcludeWord(final String excludeWord) {
this.excludeWords.add(excludeWord);
excludeWords.add(excludeWord);
}

public void setQueryFreqThreshold(final int queryFreqThreshold) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public PopularWordsResponse(final String index, final long tookMs, final List<St
this.index = index;
this.tookMs = tookMs;
this.words = words;
this.num = words.size();
num = words.size();
this.total = total;
this.items = items;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ public void setQuery(final String query) {
}

public void addTag(final String tag) {
this.tags.add(tag);
tags.add(tag);
}

public void addRole(final String role) {
this.roles.add(role);
roles.add(role);
}

public void addField(final String field) {
this.fields.add(field);
fields.add(field);
}

public void addKind(final String kind) {
this.kinds.add(kind);
kinds.add(kind);
}

public void setSuggestDetail(final boolean suggestDetail) {
Expand Down Expand Up @@ -127,7 +127,7 @@ public void setSkipDuplicateWords(final boolean skipDuplicateWords) {
}

public void addLang(final String lang) {
this.languages.add(lang);
languages.add(lang);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public SuggestResponse(final String index, final long tookMs, final List<String>
this.index = index;
this.tookMs = tookMs;
this.words = words;
this.num = words.size();
num = words.size();
this.total = total;
this.items = items;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ protected String loadIndexSettings() throws IOException {
}

protected String getSuggestAnalyzerPath() {
final Object typeObj = this.settings.get("search_engine.type");
final Object typeObj = settings.get("search_engine.type");
if (typeObj != null) {
final String path = "suggest_indices/_" + typeObj.toString() + "/suggest_analyzer.json";
if (ResourceUtil.getResourceNoException(path) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class ArraySettings {
protected ArraySettings(final SuggestSettings settings, final Client client, final String settingsIndexName, final String settingsId) {
this.settings = settings;
this.client = client;
this.arraySettingsIndexName = createArraySettingsIndexName(settingsIndexName);
arraySettingsIndexName = createArraySettingsIndexName(settingsIndexName);
this.settingsId = settingsId;
createMappingIfEmpty(arraySettingsIndexName, settingsId, client);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class BadWordSettings {

protected BadWordSettings(final SuggestSettings settings, final Client client, final String settingsIndexName,
final String settingsId) {
this.arraySettings = new ArraySettings(settings, client, settingsIndexName, settingsId) {
arraySettings = new ArraySettings(settings, client, settingsIndexName, settingsId) {
@Override
protected String createArraySettingsIndexName(final String settingsIndexName) {
return settingsIndexName + "_badword";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ElevateWordSettings {

protected ElevateWordSettings(final SuggestSettings settings, final Client client, final String settingsIndexName,
final String settingsId) {
this.arraySettings = new ArraySettings(settings, client, settingsIndexName, settingsId) {
arraySettings = new ArraySettings(settings, client, settingsIndexName, settingsId) {
@Override
protected String createArraySettingsIndexName(final String settingsIndexName) {
return settingsIndexName + "_elevate";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public SuggestSettings(final Client client, final String settingsId, final Map<S
this.initialSettings = initialSettings;
this.timeoutSettings = timeoutSettings;

this.badWordIndexName = settingsIndexName + "-badword";
this.elevateWordIndexName = settingsIndexName + "-elevateword";
badWordIndexName = settingsIndexName + "-badword";
elevateWordIndexName = settingsIndexName + "-elevateword";
}

public void init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static List<String> getKeywords(final String q, final String[] fields) {
}
for (final TermQuery tq : termQueryList) {
final String text = tq.getTerm().text();
if ((0 == text.length()) || keywords.contains(text)) {
if (0 == text.length() || keywords.contains(text)) {
continue;
}
keywords.add(text);
Expand Down

0 comments on commit e166c7e

Please sign in to comment.