You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/02/16 13:41:00 UTC
[GitHub] [lucene-solr] donnerpeter opened a new pull request #2376: LUCENE-9778: Hunspell: speed up input conversion
donnerpeter opened a new pull request #2376:
URL: https://github.com/apache/lucene-solr/pull/2376
<!--
_(If you are a project committer then you may remove some/all of the following template.)_
Before creating a pull request, please file an issue in the ASF Jira system for Lucene or Solr:
* https://issues.apache.org/jira/projects/LUCENE
* https://issues.apache.org/jira/projects/SOLR
You will need to create an account in Jira in order to create an issue.
The title of the PR should reference the Jira issue number in the form:
* LUCENE-####: <short description of problem or changes>
* SOLR-####: <short description of problem or changes>
LUCENE and SOLR must be fully capitalized. A short description helps people scanning pull requests for items they can work on.
Properly referencing the issue in the title ensures that Jira is correctly updated with code review comments and commits. -->
# Description
Every input is converted to StringBuilder and then back, and an ICONV FST is (expensively) traversed for each char of the input. That takes some CPU time, up to 15% for English.
# Solution
Extract ICONV/OCONV analysis into a new `ConvTable` class
Keep there hashes of first chars of all keys to quickly check if this table would do anything at all
Initialize FST stuff lazily on traversal
Add `Dictionary.needsInputCleaning(word)` to check if input conversion may do anything, and use it to avoid calling it where possible
# Tests
No behavior change; `TestDictionary` adapted to the new architecture
# Checklist
Please review the following and check all that apply:
- [x] I have reviewed the guidelines for [How to Contribute](https://wiki.apache.org/solr/HowToContribute) and my code conforms to the standards described there to the best of my ability.
- [x] I have created a Jira issue and added the issue ID to my pull request title.
- [x] I have given Solr maintainers [access](https://help.github.com/en/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork) to contribute to my PR branch. (optional but recommended)
- [x] I have developed this patch against the `master` branch.
- [x] I have run `./gradlew check`.
- [ ] I have added tests for my changes.
- [ ] I have added documentation for the [Ref Guide](https://github.com/apache/lucene-solr/tree/master/solr/solr-ref-guide) (for Solr changes only).
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] donnerpeter commented on a change in pull request #2376: LUCENE-9778: Hunspell: speed up input conversion
Posted by GitBox <gi...@apache.org>.
donnerpeter commented on a change in pull request #2376:
URL: https://github.com/apache/lucene-solr/pull/2376#discussion_r576832415
##########
File path: lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
##########
@@ -1085,8 +1062,9 @@ private void writeNormalizedWordEntry(
int sep = flagSep < 0 ? morphSep : flagSep;
CharSequence toWrite;
- if (needsInputCleaning) {
- cleanInput(line, sep, reuse);
+ String beforeSep = line.substring(0, sep);
+ if (needsInputCleaning(beforeSep)) {
Review comment:
Removed the `cleanInput` overload with prefixLen as it complicates code and doesn't seem to be of benefit
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] donnerpeter commented on a change in pull request #2376: LUCENE-9778: Hunspell: speed up input conversion
Posted by GitBox <gi...@apache.org>.
donnerpeter commented on a change in pull request #2376:
URL: https://github.com/apache/lucene-solr/pull/2376#discussion_r576830326
##########
File path: lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ConvTable.java
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.hunspell;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.TreeMap;
+import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.FixedBitSet;
+import org.apache.lucene.util.IntsRefBuilder;
+import org.apache.lucene.util.fst.CharSequenceOutputs;
+import org.apache.lucene.util.fst.FST;
+import org.apache.lucene.util.fst.FSTCompiler;
+import org.apache.lucene.util.fst.Outputs;
+import org.apache.lucene.util.fst.Util;
+
+/** ICONV or OCONV replacement table */
+class ConvTable {
+ private final FST<CharsRef> fst;
+ private final FixedBitSet firstCharHashes;
Review comment:
An optimization to avoid going into FST on every char
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] donnerpeter commented on a change in pull request #2376: LUCENE-9778: Hunspell: speed up input conversion
Posted by GitBox <gi...@apache.org>.
donnerpeter commented on a change in pull request #2376:
URL: https://github.com/apache/lucene-solr/pull/2376#discussion_r576830844
##########
File path: lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ConvTable.java
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.hunspell;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.TreeMap;
+import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.FixedBitSet;
+import org.apache.lucene.util.IntsRefBuilder;
+import org.apache.lucene.util.fst.CharSequenceOutputs;
+import org.apache.lucene.util.fst.FST;
+import org.apache.lucene.util.fst.FSTCompiler;
+import org.apache.lucene.util.fst.Outputs;
+import org.apache.lucene.util.fst.Util;
+
+/** ICONV or OCONV replacement table */
+class ConvTable {
+ private final FST<CharsRef> fst;
+ private final FixedBitSet firstCharHashes;
+ private final int mod;
+
+ ConvTable(TreeMap<String, String> mappings) {
+ mod = Math.max(256, Integer.highestOneBit(mappings.size()) << 1);
+ firstCharHashes = new FixedBitSet(mod);
+
+ try {
+ Outputs<CharsRef> outputs = CharSequenceOutputs.getSingleton();
+ FSTCompiler<CharsRef> fstCompiler = new FSTCompiler<>(FST.INPUT_TYPE.BYTE2, outputs);
+ IntsRefBuilder scratchInts = new IntsRefBuilder();
+ for (Map.Entry<String, String> entry : mappings.entrySet()) {
+ String key = entry.getKey();
+ assert key.length() > 0;
+ firstCharHashes.set(key.charAt(0) % mod);
+ Util.toUTF16(key, scratchInts);
+ fstCompiler.add(scratchInts.get(), new CharsRef(entry.getValue()));
+ }
+
+ fst = fstCompiler.compile();
+ } catch (IOException bogus) {
+ throw new RuntimeException(bogus);
+ }
+ }
+
+ void applyMappings(StringBuilder sb) {
Review comment:
Moved from Dictionary except minor changes (see below)
##########
File path: lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ConvTable.java
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.hunspell;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.TreeMap;
+import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.FixedBitSet;
+import org.apache.lucene.util.IntsRefBuilder;
+import org.apache.lucene.util.fst.CharSequenceOutputs;
+import org.apache.lucene.util.fst.FST;
+import org.apache.lucene.util.fst.FSTCompiler;
+import org.apache.lucene.util.fst.Outputs;
+import org.apache.lucene.util.fst.Util;
+
+/** ICONV or OCONV replacement table */
+class ConvTable {
+ private final FST<CharsRef> fst;
+ private final FixedBitSet firstCharHashes;
+ private final int mod;
+
+ ConvTable(TreeMap<String, String> mappings) {
+ mod = Math.max(256, Integer.highestOneBit(mappings.size()) << 1);
+ firstCharHashes = new FixedBitSet(mod);
+
+ try {
+ Outputs<CharsRef> outputs = CharSequenceOutputs.getSingleton();
+ FSTCompiler<CharsRef> fstCompiler = new FSTCompiler<>(FST.INPUT_TYPE.BYTE2, outputs);
+ IntsRefBuilder scratchInts = new IntsRefBuilder();
+ for (Map.Entry<String, String> entry : mappings.entrySet()) {
+ String key = entry.getKey();
+ assert key.length() > 0;
+ firstCharHashes.set(key.charAt(0) % mod);
+ Util.toUTF16(key, scratchInts);
+ fstCompiler.add(scratchInts.get(), new CharsRef(entry.getValue()));
+ }
+
+ fst = fstCompiler.compile();
+ } catch (IOException bogus) {
+ throw new RuntimeException(bogus);
+ }
+ }
+
+ void applyMappings(StringBuilder sb) {
+ FST.BytesReader bytesReader = null;
+ FST.Arc<CharsRef> firstArc = null;
+ FST.Arc<CharsRef> arc = null;
Review comment:
These variables are now initialized lazily
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] dweiss commented on a change in pull request #2376: LUCENE-9778: Hunspell: speed up input conversion
Posted by GitBox <gi...@apache.org>.
dweiss commented on a change in pull request #2376:
URL: https://github.com/apache/lucene-solr/pull/2376#discussion_r577368889
##########
File path: lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ConvTable.java
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.hunspell;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.TreeMap;
+import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.FixedBitSet;
+import org.apache.lucene.util.IntsRefBuilder;
+import org.apache.lucene.util.fst.CharSequenceOutputs;
+import org.apache.lucene.util.fst.FST;
+import org.apache.lucene.util.fst.FSTCompiler;
+import org.apache.lucene.util.fst.Outputs;
+import org.apache.lucene.util.fst.Util;
+
+/** ICONV or OCONV replacement table */
+class ConvTable {
+ private final FST<CharsRef> fst;
+ private final FixedBitSet firstCharHashes;
Review comment:
It's sort of a bloom filter, right?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] dweiss merged pull request #2376: LUCENE-9778: Hunspell: speed up input conversion
Posted by GitBox <gi...@apache.org>.
dweiss merged pull request #2376:
URL: https://github.com/apache/lucene-solr/pull/2376
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] donnerpeter commented on a change in pull request #2376: LUCENE-9778: Hunspell: speed up input conversion
Posted by GitBox <gi...@apache.org>.
donnerpeter commented on a change in pull request #2376:
URL: https://github.com/apache/lucene-solr/pull/2376#discussion_r577387829
##########
File path: lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ConvTable.java
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.hunspell;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.TreeMap;
+import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.FixedBitSet;
+import org.apache.lucene.util.IntsRefBuilder;
+import org.apache.lucene.util.fst.CharSequenceOutputs;
+import org.apache.lucene.util.fst.FST;
+import org.apache.lucene.util.fst.FSTCompiler;
+import org.apache.lucene.util.fst.Outputs;
+import org.apache.lucene.util.fst.Util;
+
+/** ICONV or OCONV replacement table */
+class ConvTable {
+ private final FST<CharsRef> fst;
+ private final FixedBitSet firstCharHashes;
Review comment:
Yes, a very simple one
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] donnerpeter commented on a change in pull request #2376: LUCENE-9778: Hunspell: speed up input conversion
Posted by GitBox <gi...@apache.org>.
donnerpeter commented on a change in pull request #2376:
URL: https://github.com/apache/lucene-solr/pull/2376#discussion_r576830544
##########
File path: lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ConvTable.java
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.hunspell;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.TreeMap;
+import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.FixedBitSet;
+import org.apache.lucene.util.IntsRefBuilder;
+import org.apache.lucene.util.fst.CharSequenceOutputs;
+import org.apache.lucene.util.fst.FST;
+import org.apache.lucene.util.fst.FSTCompiler;
+import org.apache.lucene.util.fst.Outputs;
+import org.apache.lucene.util.fst.Util;
+
+/** ICONV or OCONV replacement table */
+class ConvTable {
+ private final FST<CharsRef> fst;
+ private final FixedBitSet firstCharHashes;
+ private final int mod;
+
+ ConvTable(TreeMap<String, String> mappings) {
+ mod = Math.max(256, Integer.highestOneBit(mappings.size()) << 1);
+ firstCharHashes = new FixedBitSet(mod);
+
+ try {
+ Outputs<CharsRef> outputs = CharSequenceOutputs.getSingleton();
Review comment:
Moved from Dictionary
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] donnerpeter commented on a change in pull request #2376: LUCENE-9778: Hunspell: speed up input conversion
Posted by GitBox <gi...@apache.org>.
donnerpeter commented on a change in pull request #2376:
URL: https://github.com/apache/lucene-solr/pull/2376#discussion_r576831161
##########
File path: lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ConvTable.java
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.hunspell;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.TreeMap;
+import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.FixedBitSet;
+import org.apache.lucene.util.IntsRefBuilder;
+import org.apache.lucene.util.fst.CharSequenceOutputs;
+import org.apache.lucene.util.fst.FST;
+import org.apache.lucene.util.fst.FSTCompiler;
+import org.apache.lucene.util.fst.Outputs;
+import org.apache.lucene.util.fst.Util;
+
+/** ICONV or OCONV replacement table */
+class ConvTable {
+ private final FST<CharsRef> fst;
+ private final FixedBitSet firstCharHashes;
+ private final int mod;
+
+ ConvTable(TreeMap<String, String> mappings) {
+ mod = Math.max(256, Integer.highestOneBit(mappings.size()) << 1);
+ firstCharHashes = new FixedBitSet(mod);
+
+ try {
+ Outputs<CharsRef> outputs = CharSequenceOutputs.getSingleton();
+ FSTCompiler<CharsRef> fstCompiler = new FSTCompiler<>(FST.INPUT_TYPE.BYTE2, outputs);
+ IntsRefBuilder scratchInts = new IntsRefBuilder();
+ for (Map.Entry<String, String> entry : mappings.entrySet()) {
+ String key = entry.getKey();
+ assert key.length() > 0;
+ firstCharHashes.set(key.charAt(0) % mod);
+ Util.toUTF16(key, scratchInts);
+ fstCompiler.add(scratchInts.get(), new CharsRef(entry.getValue()));
+ }
+
+ fst = fstCompiler.compile();
+ } catch (IOException bogus) {
+ throw new RuntimeException(bogus);
+ }
+ }
+
+ void applyMappings(StringBuilder sb) {
+ FST.BytesReader bytesReader = null;
+ FST.Arc<CharsRef> firstArc = null;
+ FST.Arc<CharsRef> arc = null;
+
+ int longestMatch;
+ CharsRef longestOutput;
+
+ for (int i = 0; i < sb.length(); i++) {
+ if (!mightReplaceChar(sb.charAt(i))) {
Review comment:
Avoid going to FST on non-suspicious chars
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] donnerpeter commented on a change in pull request #2376: LUCENE-9778: Hunspell: speed up input conversion
Posted by GitBox <gi...@apache.org>.
donnerpeter commented on a change in pull request #2376:
URL: https://github.com/apache/lucene-solr/pull/2376#discussion_r576834208
##########
File path: lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
##########
@@ -1571,14 +1549,28 @@ boolean hasFlag(int entryId, char flag) {
return flagLookup.hasFlag(entryId, flag);
}
- CharSequence cleanInput(CharSequence input, StringBuilder reuse) {
- return cleanInput(input, input.length(), reuse);
+ boolean mayNeedInputCleaning() {
+ return ignoreCase || ignore != null || iconv != null;
+ }
+
+ boolean needsInputCleaning(CharSequence input) {
+ if (mayNeedInputCleaning()) {
+ for (int i = 0; i < input.length(); i++) {
+ char ch = input.charAt(i);
+ if (ignore != null && Arrays.binarySearch(ignore, ch) >= 0
+ || ignoreCase && caseFold(ch) != ch
+ || iconv != null && iconv.mightReplaceChar(ch)) {
Review comment:
Ideally `cleanInput` would check all this and just return its input if there's nothing to change, but that's not terribly trivial if we want to avoid allocations with its `StringBuilder reuse` parameter. Maybe later.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org