Skip to content

Commit e65ae1f

Browse files
feature(EJ2-59143): Moved SpellChecker cache count related changes.
1 parent 223d1b0 commit e65ae1f

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ EXPOSE 80
44
ENV SYNCFUSION_LICENSE_KEY=""
55
ENV SPELLCHECK_DICTIONARY_PATH=""
66
ENV SPELLCHECK_JSON_FILENAME=""
7+
ENV SPELLCHECK_CACHE_COUNT=""
78
FROM mcr.microsoft.com/dotnet/sdk:2.1 AS build
89

910
WORKDIR /source

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ The JSON file should contain the language-wise spell check dictionary configurat
153153
]
154154
```
155155

156+
By default, the spell checker holds only one language dictionary in memory. If you want to hold multiple dictionaries in memory, then you must set the required count to environment variable `SPELLCHECK_CACHE_COUNT` in Docker compose file. For more information, please refer [spell check documentation](https://ej2.syncfusion.com/documentation/document-editor/spell-check)
157+
156158
A JSON file is included in the default resource directory `/app/Data` of this Docker image with the name `spellcheck.json`. You can add a new file with your own spell check dictionary configurations.
157159

158160
If you customize it, then you must set the new file name to environment variable `SPELLCHECK_JSON_FILENAME` in Docker compose file like below,
@@ -166,6 +168,7 @@ services:
166168
#Provide your license key for activation
167169
SYNCFUSION_LICENSE_KEY: YOUR_LICENSE_KEY
168170
SPELLCHECK_DICTIONARY_PATH: data
171+
SPELLCHECK_CACHE_COUNT: 2
169172
SPELLCHECK_JSON_FILENAME: spellcheck1.json
170173
volumes:
171174
- ./data:/app/data

src/ej2-documenteditor-server/Controllers/DocumentEditorController.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,11 @@ namespace EJ2DocumentEditorServer.Controllers
2121
public class DocumentEditorController : Controller
2222
{
2323
private readonly IHostingEnvironment _hostingEnvironment;
24-
List<DictionaryData> spellDictionary;
25-
string personalDictPath;
2624
string path;
2725
public DocumentEditorController(IHostingEnvironment hostingEnvironment)
2826
{
29-
_hostingEnvironment = hostingEnvironment;
30-
spellDictionary = Startup.spellDictCollection;
27+
_hostingEnvironment = hostingEnvironment;
3128
path = Startup.path;
32-
personalDictPath = Startup.personalDictPath;
3329
}
3430

3531
[AcceptVerbs("Post")]
@@ -62,7 +58,7 @@ public string SpellCheck([FromBody] SpellCheckJsonData spellChecker)
6258
{
6359
try
6460
{
65-
SpellChecker spellCheck = new SpellChecker(spellDictionary,personalDictPath);
61+
SpellChecker spellCheck = new SpellChecker();
6662
spellCheck.GetSuggestions(spellChecker.LanguageID, spellChecker.TexttoCheck, spellChecker.CheckSpelling, spellChecker.CheckSuggestion, spellChecker.AddWord);
6763
return Newtonsoft.Json.JsonConvert.SerializeObject(spellCheck);
6864
}
@@ -86,7 +82,7 @@ public string SpellCheckByPage([FromBody] SpellCheckJsonData spellChecker)
8682
{
8783
try
8884
{
89-
SpellChecker spellCheck = new SpellChecker(spellDictionary,personalDictPath);
85+
SpellChecker spellCheck = new SpellChecker();
9086
spellCheck.CheckSpelling(spellChecker.LanguageID, spellChecker.TexttoCheck);
9187
return Newtonsoft.Json.JsonConvert.SerializeObject(spellCheck);
9288
}

src/ej2-documenteditor-server/Startup.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ namespace EJ2DocumentEditorServer
2424
{
2525
public class Startup
2626
{
27-
internal static List<DictionaryData> spellDictCollection;
2827
internal static string path;
29-
internal static string personalDictPath;
3028
public Startup(IConfiguration configuration, IHostingEnvironment env)
3129
{
3230
var builder = new ConfigurationBuilder()
@@ -38,6 +36,11 @@ public Startup(IConfiguration configuration, IHostingEnvironment env)
3836
Configuration = builder.Build();
3937
path = Configuration["SPELLCHECK_DICTIONARY_PATH"];
4038
string jsonFileName = Configuration["SPELLCHECK_JSON_FILENAME"];
39+
int cacheCount;
40+
if (!int.TryParse(Configuration["SPELLCHECK_CACHE_COUNT"], out cacheCount))
41+
{
42+
cacheCount = 1;
43+
}
4144
//check the spell check dictionary path environment variable value and assign default data folder
4245
//if it is null.
4346
path = string.IsNullOrEmpty(path) ? Path.Combine(env.ContentRootPath, "Data") : Path.Combine(env.ContentRootPath, path);
@@ -47,13 +50,15 @@ public Startup(IConfiguration configuration, IHostingEnvironment env)
4750
{
4851
string jsonImport = System.IO.File.ReadAllText(jsonFileName);
4952
List<DictionaryData> spellChecks = JsonConvert.DeserializeObject<List<DictionaryData>>(jsonImport);
50-
spellDictCollection = new List<DictionaryData>();
53+
List<DictionaryData> spellDictCollection = new List<DictionaryData>();
54+
string personalDictPath = string.Empty;
5155
//construct the dictionary file path using customer provided path and dictionary name
5256
foreach (var spellCheck in spellChecks)
5357
{
5458
spellDictCollection.Add(new DictionaryData(spellCheck.LanguadeID, Path.Combine(path, spellCheck.DictionaryPath), Path.Combine(path, spellCheck.AffixPath)));
5559
personalDictPath = Path.Combine(path, spellCheck.PersonalDictPath);
5660
}
61+
SpellChecker.InitializeDictionaries(spellDictCollection, personalDictPath, cacheCount);
5762
}
5863
}
5964

src/ej2-documenteditor-server/appsettings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"SYNCFUSION_LICENSE_KEY": "",
33
"SPELLCHECK_DICTIONARY_PATH": "",
4+
"SPELLCHECK_CACHE_COUNT": "",
45
"Logging": {
56
"IncludeScopes": false,
67
"Debug": {

0 commit comments

Comments
 (0)