@@ -23,14 +23,18 @@ 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 ;
3438
3539 public static String namedVCPath = "" ;
3640 public static boolean isTest = false ;
@@ -97,6 +101,8 @@ public static void updateConfigurations (Properties prop) {
97101// String maxCharContextSize = prop.getProperty("krill.context.max.char");
98102 String defaultSearchContextLength = prop .getProperty ("krill.search.context.default" );
99103 String maxTextSizeValue = prop .getProperty ("krill.index.textSize.max" );
104+ String maxKwicChar = prop .getProperty ("krill.kwic.max.char" );
105+ String safeCharBounds = prop .getProperty ("krill.snippet.safeCharBounds" );
100106
101107 try {
102108 if (maxTokenMatchSize != null ) {
@@ -128,39 +134,21 @@ public static void updateConfigurations (Properties prop) {
128134 }
129135
130136 }
137+ if (maxKwicChar != null ) {
138+ KrillProperties .maxKwicCharSize = Integer .parseInt (maxKwicChar );
139+ if (KrillProperties .maxKwicCharSize < 0 )
140+ KrillProperties .maxKwicCharSize = 0 ;
141+ }
142+ if (safeCharBounds != null ) {
143+ KrillProperties .safeSnippetCharBounds = Boolean .parseBoolean (safeCharBounds );
144+ }
131145 }
132146 catch (NumberFormatException e ) {
133147 log .error ("A Krill property expects numerical values: "
134148 + e .getMessage ());
135149 };
136150
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- }
151+ // Keep default unless explicitly overridden by property
164152
165153 String p = prop .getProperty ("krill.test" , "false" );
166154 isTest = Boolean .parseBoolean (p );
@@ -174,12 +162,11 @@ public static void updateConfigurations (Properties prop) {
174162 secret = prop .getProperty ("krill.secretB64" , "" );
175163
176164 log .info ("Effective krill.kwic.max.token = {}" , KrillProperties .maxTokenKwicSize );
165+ log .info ("Effective krill.snippet.safeCharBounds = {}" , KrillProperties .safeSnippetCharBounds );
166+ log .info ("Effective krill.kwic.max.char = {}" , KrillProperties .maxKwicCharSize );
177167 }
178168
179169 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 ;
183170 return maxTokenKwicSize ;
184171 }
185172
0 commit comments