fix Echo 有两重定向词条,这时显示在侯选列表中
Browse files- readme.txt +64 -0
- wpfmdict/EchodictWindow.xaml.cs +39 -11
- wpfmdict/MdxReader.cs +9 -4
readme.txt
CHANGED
|
@@ -1048,6 +1048,70 @@ goldendict-ng C++ 代码通过拦截 entry:// 协议并将其转换为内部查
|
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
|
|
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
+
`e:\huggingface\goldendict-ng\wpfmdict` 目前的情况是搜 echo 词条会连同 Echo 的词条内容一同出现在 echo 的内容里, mdx 里原始文本是这样的:echo
|
| 1052 |
+
...内容省略
|
| 1053 |
+
</>
|
| 1054 |
+
Echo
|
| 1055 |
+
@@@LINK=Echo¹
|
| 1056 |
+
</>
|
| 1057 |
+
Echo
|
| 1058 |
+
@@@LINK=Echo²
|
| 1059 |
+
</> 我需要搜 echo 时不出现 Echo 的内容,但是把 Echo 这两个不同的条目,既 @@@LINK=Echo¹ 和 @@@LINK=Echo² 这两条重定向条目放在 UI 搜索框下面的列表里,供用户稍后点击查询
|
| 1060 |
+
|
| 1061 |
+
The required changes have been implemented to address the issue where searching for "echo" displayed content from "Echo" entries, and to ensure "Echo" redirect entries appear in the suggestion list.
|
| 1062 |
+
|
| 1063 |
+
### Changes Summary
|
| 1064 |
+
1. MdxReader.cs Update :
|
| 1065 |
+
|
| 1066 |
+
- Duplicate Headword Support : Changed the Index structure from Dictionary<string, long> to Dictionary<string, List<int>> . This allows the application to store and retrieve multiple entries that share the same case-insensitive key (e.g., "echo" and "Echo").
|
| 1067 |
+
- Data Retrieval : Added an Entries list to store MdxEntry structs (containing Headword and Offset ) and updated GetDefinition to retrieve definitions by entry index.
|
| 1068 |
+
- Compatibility : Restored GetRecordData(string) and GetResource(string) methods to maintain compatibility with Dictionary.cs , ensuring that file resource loading continues to work correctly.
|
| 1069 |
+
2. EchodictWindow.xaml.cs Update :
|
| 1070 |
+
|
| 1071 |
+
- Search Logic Refactoring : Updated the Search method to handle the new List<int> returned by the index lookup.
|
| 1072 |
+
- Content Filtering : Implemented strict case matching ( StringComparison.Ordinal ) for content display. Now, when searching for "echo", only the content for the exact match "echo" is displayed.
|
| 1073 |
+
- Suggestion List Enhancement : Modified the search loop to iterate through all case-insensitive matches (e.g., "Echo" redirects). If an entry is a redirect (starts with @@@LINK= ), its target is added to the suggestion list ( WordList ) regardless of case, fulfilling the requirement to show "Echo" redirects in the list.
|
| 1074 |
+
### Outcome
|
| 1075 |
+
- Search "echo" :
|
| 1076 |
+
- Main View : Displays only the content for the exact lowercase "echo" entry.
|
| 1077 |
+
- Suggestion List : Includes the targets of the "Echo" redirect entries (e.g., "Echo¹", "Echo²").
|
| 1078 |
+
- Search "Echo" :
|
| 1079 |
+
- Main View : Will display content for exact "Echo" matches (if any non-redirect content exists).
|
| 1080 |
+
- Suggestion List : Includes redirect targets.
|
| 1081 |
+
You can now rebuild the project. The application will automatically rebuild the dictionary caches ( .idx files) on the next run to apply the new index format.
|
| 1082 |
+
|
| 1083 |
+
|
| 1084 |
+
|
| 1085 |
+
|
| 1086 |
+
`e:\huggingface\goldendict-ng\wpfmdict` mdx 文件解析出来的源文本是:Echo
|
| 1087 |
+
@@@LINK=Echo¹
|
| 1088 |
+
</>
|
| 1089 |
+
Echo
|
| 1090 |
+
@@@LINK=Echo²
|
| 1091 |
+
</> 我希望搜索 Echo 时,将 Echo¹ Echo² 这两个重定向词条显示在 UI 搜索框下面的那个列表中,这样用户可以手动点击 Echo¹ 或着 Echo² 实现查询这两个词条
|
| 1092 |
+
|
| 1093 |
+
|
| 1094 |
+
I've implemented the changes to support separate handling of "echo" and "Echo", ensuring that redirects appear in the suggestion list.
|
| 1095 |
+
|
| 1096 |
+
### Key Changes
|
| 1097 |
+
1. MdxReader.cs Update :
|
| 1098 |
+
|
| 1099 |
+
- Added a resolveLinks parameter to GetDefinition (defaulting to true for backward compatibility, but allowing false for raw data access).
|
| 1100 |
+
- This allows the search logic to inspect the raw content of an entry to see if it's a redirect ( @@@LINK= ) without automatically following it.
|
| 1101 |
+
2. EchodictWindow.xaml.cs Update :
|
| 1102 |
+
|
| 1103 |
+
- Modified the search loop to call GetDefinition(index, false) to get the raw content.
|
| 1104 |
+
- Redirect Handling : If an entry is a redirect (starts with @@@LINK= ), it parses the link target and adds it to the WordList (suggestion list) regardless of case matching. This ensures "Echo¹" and "Echo²" appear in the list when searching for "echo".
|
| 1105 |
+
- Content Display : Content is only displayed if the headword exactly matches the search query (case-sensitive StringComparison.Ordinal ).
|
| 1106 |
+
- Empty Result Handling : If a query matches only redirects (like "Echo" -> "Echo¹"), and no content is displayed, it now shows a "Multiple candidates found" message instead of a blank result.
|
| 1107 |
+
### Result
|
| 1108 |
+
When you search for "echo":
|
| 1109 |
+
|
| 1110 |
+
1. Content : Only the definition for the exact lowercase "echo" will be displayed.
|
| 1111 |
+
2. Suggestions : The WordList below the search box will be populated with "Echo¹" and "Echo²" (from the "Echo" redirect entries), allowing you to click them to view their specific definitions.
|
| 1112 |
+
You can now rebuild and run the application. The dictionary index will automatically update on the next run.
|
| 1113 |
+
|
| 1114 |
+
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
wpfmdict/EchodictWindow.xaml.cs
CHANGED
|
@@ -397,16 +397,19 @@ namespace Echodict
|
|
| 397 |
string anchorName = $"dict_{dict.Id}";
|
| 398 |
StringBuilder dictContent = new StringBuilder();
|
| 399 |
bool hasContent = false;
|
|
|
|
| 400 |
|
| 401 |
foreach (int index in entryIndices)
|
| 402 |
{
|
| 403 |
var entry = dict.Mdx.Entries[index];
|
| 404 |
-
string? def = dict.Mdx.GetDefinition(index);
|
| 405 |
|
| 406 |
if (string.IsNullOrEmpty(def)) continue;
|
| 407 |
|
|
|
|
|
|
|
| 408 |
// Check for redirects to populate suggestion list
|
| 409 |
-
if (
|
| 410 |
{
|
| 411 |
if (updateWordList)
|
| 412 |
{
|
|
@@ -428,15 +431,24 @@ namespace Echodict
|
|
| 428 |
// Check for Exact Match to display content
|
| 429 |
if (entry.Headword.Equals(query, StringComparison.Ordinal))
|
| 430 |
{
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
}
|
| 441 |
}
|
| 442 |
|
|
@@ -457,6 +469,22 @@ namespace Echodict
|
|
| 457 |
sb.Append(dictContent.ToString());
|
| 458 |
sb.Append("<br/><br/>");
|
| 459 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
}
|
| 461 |
}
|
| 462 |
|
|
|
|
| 397 |
string anchorName = $"dict_{dict.Id}";
|
| 398 |
StringBuilder dictContent = new StringBuilder();
|
| 399 |
bool hasContent = false;
|
| 400 |
+
bool hasRedirects = false;
|
| 401 |
|
| 402 |
foreach (int index in entryIndices)
|
| 403 |
{
|
| 404 |
var entry = dict.Mdx.Entries[index];
|
| 405 |
+
string? def = dict.Mdx.GetDefinition(index, false); // Get raw definition (no redirect following)
|
| 406 |
|
| 407 |
if (string.IsNullOrEmpty(def)) continue;
|
| 408 |
|
| 409 |
+
bool isRedirect = def.StartsWith("@@@LINK=");
|
| 410 |
+
|
| 411 |
// Check for redirects to populate suggestion list
|
| 412 |
+
if (isRedirect)
|
| 413 |
{
|
| 414 |
if (updateWordList)
|
| 415 |
{
|
|
|
|
| 431 |
// Check for Exact Match to display content
|
| 432 |
if (entry.Headword.Equals(query, StringComparison.Ordinal))
|
| 433 |
{
|
| 434 |
+
if (isRedirect)
|
| 435 |
+
{
|
| 436 |
+
// It's a redirect that exactly matches the query.
|
| 437 |
+
// We mark hasRedirects so we can show a message if no other content is found.
|
| 438 |
+
hasRedirects = true;
|
| 439 |
+
}
|
| 440 |
+
else
|
| 441 |
+
{
|
| 442 |
+
// Rewrite relative links to include dictionary ID for isolation
|
| 443 |
+
// Matches src="..." or href="..." where value doesn't start with http, https, data:, #, or entry:
|
| 444 |
+
string pattern = @"(?i)(src|href)=[""'](?!http|https|data:|#|entry:)([^""']+)[""']";
|
| 445 |
+
string replacement = $"$1=\"http://custom-rendering/{dict.Id}/$2\"";
|
| 446 |
+
def = System.Text.RegularExpressions.Regex.Replace(def, pattern, replacement);
|
| 447 |
+
|
| 448 |
+
dictContent.Append(def);
|
| 449 |
+
dictContent.Append("<br/>");
|
| 450 |
+
hasContent = true;
|
| 451 |
+
}
|
| 452 |
}
|
| 453 |
}
|
| 454 |
|
|
|
|
| 469 |
sb.Append(dictContent.ToString());
|
| 470 |
sb.Append("<br/><br/>");
|
| 471 |
}
|
| 472 |
+
else if (hasRedirects)
|
| 473 |
+
{
|
| 474 |
+
// Found only redirects for this query in this dictionary
|
| 475 |
+
found = true; // Still consider it found
|
| 476 |
+
|
| 477 |
+
ListBoxItem resultItem = new ListBoxItem();
|
| 478 |
+
resultItem.Content = dict.Name;
|
| 479 |
+
resultItem.Tag = anchorName;
|
| 480 |
+
resultItem.MouseDoubleClick += ResultItem_MouseDoubleClick;
|
| 481 |
+
DictsList.Items.Add(resultItem);
|
| 482 |
+
|
| 483 |
+
sb.Append($"<a name=\"{anchorName}\"></a>");
|
| 484 |
+
sb.Append($"<h3>{query} <small>({dict.Name})</small></h3>");
|
| 485 |
+
sb.Append("<p><i>Multiple candidates found. Please select from the list.</i></p>");
|
| 486 |
+
sb.Append("<hr/>");
|
| 487 |
+
}
|
| 488 |
}
|
| 489 |
}
|
| 490 |
|
wpfmdict/MdxReader.cs
CHANGED
|
@@ -305,10 +305,15 @@ namespace Echodict
|
|
| 305 |
|
| 306 |
public string? GetDefinition(int entryIndex)
|
| 307 |
{
|
| 308 |
-
return GetDefinitionInternal(entryIndex, new HashSet<int>());
|
| 309 |
}
|
| 310 |
|
| 311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
{
|
| 313 |
if (visited.Contains(entryIndex)) return null; // Cycle detection
|
| 314 |
visited.Add(entryIndex);
|
|
@@ -342,7 +347,7 @@ namespace Echodict
|
|
| 342 |
}
|
| 343 |
|
| 344 |
// Handle internal redirects
|
| 345 |
-
if (text.StartsWith("@@@LINK="))
|
| 346 |
{
|
| 347 |
// Check for multiple links
|
| 348 |
if (text.IndexOf("@@@LINK=", 1) != -1)
|
|
@@ -369,7 +374,7 @@ namespace Echodict
|
|
| 369 |
break;
|
| 370 |
}
|
| 371 |
}
|
| 372 |
-
var targetDef = GetDefinitionInternal(bestMatch, visited);
|
| 373 |
if (targetDef != null) return targetDef;
|
| 374 |
}
|
| 375 |
}
|
|
|
|
| 305 |
|
| 306 |
public string? GetDefinition(int entryIndex)
|
| 307 |
{
|
| 308 |
+
return GetDefinitionInternal(entryIndex, new HashSet<int>(), true);
|
| 309 |
}
|
| 310 |
|
| 311 |
+
public string? GetDefinition(int entryIndex, bool resolveLinks)
|
| 312 |
+
{
|
| 313 |
+
return GetDefinitionInternal(entryIndex, new HashSet<int>(), resolveLinks);
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
private string? GetDefinitionInternal(int entryIndex, HashSet<int> visited, bool resolveLinks)
|
| 317 |
{
|
| 318 |
if (visited.Contains(entryIndex)) return null; // Cycle detection
|
| 319 |
visited.Add(entryIndex);
|
|
|
|
| 347 |
}
|
| 348 |
|
| 349 |
// Handle internal redirects
|
| 350 |
+
if (resolveLinks && text.StartsWith("@@@LINK="))
|
| 351 |
{
|
| 352 |
// Check for multiple links
|
| 353 |
if (text.IndexOf("@@@LINK=", 1) != -1)
|
|
|
|
| 374 |
break;
|
| 375 |
}
|
| 376 |
}
|
| 377 |
+
var targetDef = GetDefinitionInternal(bestMatch, visited, true);
|
| 378 |
if (targetDef != null) return targetDef;
|
| 379 |
}
|
| 380 |
}
|