@@ -23,14 +23,20 @@ public class KrillProperties {
2323
2424 public static int maxTokenMatchSize = 50 ;
2525 public static int maxTokenContextSize = 60 ;
26- // New: Total KWIC size cap (match + left + right)
27- // Default to derived value even if properties are never loaded
26+ // Total KWIC size cap (match + left + right)
27+ // Default derived from legacy match/context sizes
2828 public static int maxTokenKwicSize = (2 * maxTokenContextSize ) + maxTokenMatchSize ;
2929 public static int maxCharContextSize = 500 ;
30+ // Optional hard cap for HTML character window (0 = disabled)
31+ public static int maxKwicCharSize = 0 ;
3032 public static int defaultSearchContextLength = 6 ;
3133 public static int maxTextSize = DEFAULT_MAX_STRING_LEN ; // Default max text size
3234
3335 public static boolean matchExpansionIncludeContextSize = false ;
36+ // When true, clamp snippet end to safe char bounds if offsets are missing
37+ public static boolean safeSnippetCharBounds = false ;
38+ // When true, align HTML KWIC to the token window produced by getSnippetTokens()
39+ public static boolean enforceHtmlKwic = false ;
3440
3541 public static String namedVCPath = "" ;
3642 public static boolean isTest = false ;
@@ -97,6 +103,9 @@ public static void updateConfigurations (Properties prop) {
97103// String maxCharContextSize = prop.getProperty("krill.context.max.char");
98104 String defaultSearchContextLength = prop .getProperty ("krill.search.context.default" );
99105 String maxTextSizeValue = prop .getProperty ("krill.index.textSize.max" );
106+ String maxKwicChar = prop .getProperty ("krill.kwic.max.char" );
107+ String enforceHtmlKwicProp = prop .getProperty ("krill.kwic.enforce.html" );
108+ String safeCharBounds = prop .getProperty ("krill.snippet.safeCharBounds" );
100109
101110 try {
102111 if (maxTokenMatchSize != null ) {
@@ -128,39 +137,24 @@ public static void updateConfigurations (Properties prop) {
128137 }
129138
130139 }
140+ if (maxKwicChar != null ) {
141+ KrillProperties .maxKwicCharSize = Integer .parseInt (maxKwicChar );
142+ if (KrillProperties .maxKwicCharSize < 0 )
143+ KrillProperties .maxKwicCharSize = 0 ;
144+ }
145+ if (enforceHtmlKwicProp != null ) {
146+ KrillProperties .enforceHtmlKwic = Boolean .parseBoolean (enforceHtmlKwicProp );
147+ }
148+ if (safeCharBounds != null ) {
149+ KrillProperties .safeSnippetCharBounds = Boolean .parseBoolean (safeCharBounds );
150+ }
131151 }
132152 catch (NumberFormatException e ) {
133153 log .error ("A Krill property expects numerical values: "
134154 + e .getMessage ());
135155 };
136156
137- // Always ensure kwic cap has a sensible value, even if not configured
138- if (KrillProperties .maxTokenKwicSize <= 0 ) {
139- KrillProperties .maxTokenKwicSize = (2 * KrillProperties .maxTokenContextSize )
140- + KrillProperties .maxTokenMatchSize ;
141- }
142-
143- // Handle deprecation and fallback for KWIC size
144- if (KrillProperties .maxTokenKwicSize <= 0 ) {
145- boolean legacyMatchSet = (maxTokenMatchSize != null );
146- boolean legacyContextSet = (maxTokenContextSize != null );
147- if (legacyMatchSet || legacyContextSet ) {
148- if (legacyMatchSet )
149- log .warn ("Property 'krill.match.max.token' is deprecated. Use 'krill.kwic.max.token'." );
150- if (legacyContextSet )
151- log .warn ("Property 'krill.context.max.token' is deprecated. Use 'krill.kwic.max.token'." );
152- // Compute sensible default from deprecated settings
153- KrillProperties .maxTokenKwicSize = (2 * KrillProperties .maxTokenContextSize )
154- + KrillProperties .maxTokenMatchSize ;
155- log .warn ("Computed 'krill.kwic.max.token' as {} from deprecated settings." ,
156- KrillProperties .maxTokenKwicSize );
157- }
158- else {
159- // Neither new nor legacy; derive from current defaults
160- KrillProperties .maxTokenKwicSize = (2 * KrillProperties .maxTokenContextSize )
161- + KrillProperties .maxTokenMatchSize ;
162- }
163- }
157+ // Keep default unless explicitly overridden by property
164158
165159 String p = prop .getProperty ("krill.test" , "false" );
166160 isTest = Boolean .parseBoolean (p );
@@ -174,12 +168,12 @@ public static void updateConfigurations (Properties prop) {
174168 secret = prop .getProperty ("krill.secretB64" , "" );
175169
176170 log .info ("Effective krill.kwic.max.token = {}" , KrillProperties .maxTokenKwicSize );
171+ log .info ("Effective krill.snippet.safeCharBounds = {}" , KrillProperties .safeSnippetCharBounds );
172+ log .info ("Effective krill.kwic.max.char = {}" , KrillProperties .maxKwicCharSize );
173+ log .info ("Effective krill.kwic.enforce.html = {}" , KrillProperties .enforceHtmlKwic );
177174 }
178175
179176 public static int getMaxTokenKwicSize () {
180- // In case properties were never loaded, return a derived sensible default
181- if (maxTokenKwicSize <= 0 )
182- maxTokenKwicSize = (2 * maxTokenContextSize ) + maxTokenMatchSize ;
183177 return maxTokenKwicSize ;
184178 }
185179
0 commit comments