About this article
This article is created using an automated generation workflow powered by generative AI. It demonstrates how to make searches easier to find while preserving the original product codes using a hypothetical product ledger.Verification status: 🧪 ECMAScript specifications verified, and 6 examples of prototype HTML logic and form processing were executed in a simulated screen interface. Operation in a real browser and display in WordPress have not been confirmed.
You were told over the phone to search for "ABC123", but no product appeared. The ledger you received had the full-width "ABC123" written on it. Normalizing character widths for search makes items easier to find. However, as a result of this normalization, different products may end up looking like they have the same name.
Therefore,normalize only the values used for searching while keeping the ledger product codes and management IDs unchangedis the approach we take. A management ID is a number used to identify each product in the ledger individually. This time, we are only finding candidates. We do not process orders or rewrite the ledger.
| Testing environment | Data used | What we will not do |
|---|---|---|
| An environment where JavaScript runs. The table below can be read without executing it. | 3 hypothetical product codes | Loading the ledger, rewriting it, or placing orders |
- First test: The same input yields 1 to 2 candidates.
- Why the results change: Different scope for visual normalization
- Comparing modified values in JavaScript without saving them
- What to check for 0, 1, or multiple matches
- If using this in your own work, try searching before proceeding to the order screen
- GitHub Sample
- Reference Materials
- Glossary
First test: The same input yields 1 to 2 candidates.
Treating the search term as ABC123, compare the three lines below. In NFC, which compares full-width and half-width characters as distinct characters, there is B07 item(s). In NFKC, which aligns full-width characters into the same comparison form as half-width characters, A01 is also included as a candidate, resulting in 2 items. The entered product code has not changed, but ratherThe criteria for inclusion as a candidatehave changed. You can also verify this result in the later JavaScript section.
| Ledger management ID | Original part number | ABC123Result of searching using NFKC |
|---|---|---|
| A01 | ABC123 | Included as a candidate. The original text differs |
| B07 | ABC123 | Included as a candidate. The original text also matches |
| C28 | Supplier 1 | Not included as a candidate |
In this example, the management ID is a number that distinguishes products.A01 and B07 are on different rows and must not be automatically consolidated. An exact match for B07 is marked, butA01 the row also remains. The screen does not finalize orders or registrations. It only returns information to help verify the relevant destination.
flowchart TD
A["元品番と管理IDを入力データから読む"] --> B["検索用の比較キーを別に作る"]
B --> C["候補には元品番と管理IDを表示"]
When displaying candidates, the important thing is that both the original part number and the management ID remain visible even after the number of candidates increases. When someone says "ABC123" over the phone, you do not know whether they entered half-width characters. Even if the half-width row is found first, if the full-width row represents a different product, the staff member decides which one to use. Being easy to find and being able to determine the correct single item are two different things.
Why the results change: Different scope for visual normalization
JavaScript's normalize() normalizes strings according to Unicode rules. NFC makes it easier to compare canonically equivalent representations, such as a character written with "ka" plus a combining voiced sound mark versus a single character "ga". However, NFC does not convert full-width alphabetic characters to half-width. NFKC additionally maps compatibility characters, such as full-width alphanumeric characters and circled numbers, for comparison purposes.取引先1 When comparing using NFKC, even if the original ledger does not contain that string, 取引先① becomes a candidate.
While this behavior is convenient, it does not guarantee that the original text can be restored from the converted value. JavaScript cannot infer the intention of the staff member who used "①" and "1" distinctively. For example, bulk-modifying standardized part numbers or IDs to be passed to an external system simply because a human perceives them as similar is a separate task. Please separate the process of generating comparison strings from the process of updating the ledger.
The initial attempt ABC123 was an example comparing "full-width and half-width." Next, input 取引先1 and switch only the method. The reason 取引先① becomes a candidate under NFKC is not because the characters on the screen changed arbitrarily. It is because a comparison value was generated invisibly, and those values matched. Since you can re-read the original ① when making a selection, you can cross-reference and decide yourself even in tasks where symbols must be preserved.
Comparing modified values in JavaScript without saving them
function candidates(input, form) {
if (!input.trim()) return [];
const key = input.normalize(form);
return rows.filter(row => row.name.normalize(form) === key);
}
Inputs consisting solely of whitespace result in no candidates. In the following lines, the search query is normalized, and comparison keys following the same rule are generated from each line of the ledger. What is returned is the original line, not the normalized part number.filter retains all matching lines, so neither of two identical comparison keys will be discarded. Conversely, if you overwrite Map line by line using the comparison key as a unique key, subsequent lines will overwrite previous ones. If you are building an index for performance, make the value corresponding to the comparison key a list of IDs.
Here, trim() is merely checking whether the search query consists only of whitespace. It does not trim leading and trailing whitespace before comparison. Uppercase and lowercase letters are also distinguished.abc123 and ABC123 with trailing spaces both result in no matches in the learning material. If you decide to normalize whitespace and case, document where that rule is applied and re-verify whether existing values will cause conflicts.
Even if two lines can be converted to the same string, it does not mean they refer to the same product. For example, A01 is deprecated and B07 is a current component, but the process that compares only widths cannot understand that context. If search results are retained by management ID, humans can inspect product names and applications to make a decision. Conversely, if ledger rows are overwritten with search values, it increases the effort required later to verify which information was lost.
What to check for 0, 1, or multiple matches
| Result | Next inspection |
|---|---|
| 0 matches | Check if the original part number exists in the practice ledger. Next, check the method, uppercase/lowercase letters, and leading/trailing spaces. |
| 1 match | Verify that the original part number and management ID match. Also check whether there were other rows in the backup prior to import. |
| Multiple matches | Compare the original part number and management ID without narrowing down candidates. If unable to decide, consult the ordering source. |
flowchart TD
A["候補がゼロまたは複数"] --> B["検索条件と台帳の元値を確認"]
B --> C["管理IDで対象を選び直す"]
When a field is blank, no conditions are defined, so no order candidates are suggested. For example, if an input with a trailing space results in 0 matches, first remove only the space and compare. If you change the matching method at the same time, you will not know which one caused the issue. On the other hand, if the original row does not exist in the loaded data, changing the calculation method will not find it. Distinguishing between input issues and missing ledger entries ensures you do not fix the wrong place.
You can download index.html from the fixed material below and open it in a browser. Buttons will not function if you only view the source on GitHub. If your organization restricts the execution of local HTML files, do not change the settings; instead, follow the differences in results using the table above. Only fictitious part numbers are used for practice.
If using this in your own work, try searching before proceeding to the order screen
Suppose you receive bills of materials from three staff members. First, keep the original files as backups. Using a copy of those files, compare the conventional search with the search that normalizes notation. You do not need to transcribe all results. Pick up only the inputs that yielded differences, and compare the part numbers, management IDs, and applications provided by the ordering source.
flowchart TD
A["別の台帳へ導入を検討"] --> B["新旧で候補が変わる入力を比較"]
B --> C["元の品番を残して採否を決める"]
For handover, record "what was inputted," "which method was used," and "how many matches were found and which management ID corresponded to them" as a single set. If proceeding to the order screen, ensure that staff can review the management ID again after selecting a candidate. Do not finalize orders based solely on search results. By establishing this separation, even if you review the search conditions, it will not affect the original ledger or ordering decisions.
GitHub Sample
Fixed Material and Execution StepsPlease refer to
Reference Materials
ECMAScript: String.prototype.normalize: A standard method for normalizing strings.
Unicode Standard Annex #15: Canonical equivalence, compatibility equivalence, and NFC/NFKC.
Standardizing full-width alphanumeric characters with PowerShell Unicode normalization NFKC — A method that does not break the original data/PowerShell sample。
Glossary
Normalization: Formatting strings into a form that is easy to compare, according to rules defined by Unicode.
NFC: A method that standardizes differences where the same character is represented by different combinations. It does not standardize all differences between full-width and half-width characters.
NFKC: A method that also standardizes compatible notation differences. Different managed objects may result in the same comparison value.
Management ID: A ledger identifier used to distinguish between different products. It is maintained separately from the search string.
