KeywordInContextIndexBuilder.st
changeset 4132 f87c478424c7
parent 4131 b4294ed81d7d
child 4187 064b249c5e3d
--- a/KeywordInContextIndexBuilder.st	Thu Oct 13 17:22:49 2016 +0200
+++ b/KeywordInContextIndexBuilder.st	Thu Oct 13 18:17:14 2016 +0200
@@ -15,7 +15,7 @@
 
 Object subclass:#KeywordInContextIndexBuilder
 	instanceVariableNames:'keywordToLinesMapping excluded separatorAlgorithm
-		unquoteAlgorithm exclusionFilter'
+		unquoteAlgorithm exclusionFilter matchSorter'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Collections-Support'
@@ -293,6 +293,12 @@
     exclusionFilter := aBlock.
 !
 
+matchSorter:aSortBlock
+    "if set, matches will be enumerated in that sort order"
+    
+    matchSorter := aSortBlock.
+!
+
 separatorAlgorithm:aBlock
     "define the algorithm to split a given string into words.
      The default is to split at punctuation and whitespace
@@ -366,6 +372,9 @@
         |setOfMatches lcKey|
 
         setOfMatches := keywordToLinesMapping at:eachKey.
+        matchSorter notNil ifTrue:[
+            setOfMatches := setOfMatches asSortedCollection:matchSorter
+        ].    
         lcKey := eachKey asLowercase.
         setOfMatches do:[:eachAssoc |
             |text ref lines idx lIdx context left right word prevLine nextLine|