@@ -71,20 +71,36 @@ class PageSearchEngine(pages: List[PageEntry]):
71
71
pages.map(prematchPage(_, search)).filter(_.indices.nonEmpty)
72
72
73
73
private def prematchPage (page : PageEntry , search : String ): MatchResult =
74
+ val pagePackage = page.description
74
75
val pageName = page.shortName
76
+ val fullQualified = if page.description != " " then
77
+ page.description + " ." + pageName
78
+ else pageName
79
+
75
80
@ tailrec
76
- def prematchPageAcc (nameIndex : Int , searchIndex : Int , acc : Set [Int ], scoreAcc : Int , consecutiveMatches : Int ): MatchResult =
81
+ def prematchPageAcc (nameIndex : Int , searchIndex : Int , fullIndex : Int , acc : Set [Int ], scoreAcc : Int , consecutiveMatches : Int ): MatchResult =
82
+ println(s " pageName = $pageName, pagePackage = $pagePackage, fullQualified = $fullQualified" )
83
+ println(s " searchIndex = $searchIndex, searchLength = ${search.length}, nameIndex = $nameIndex, pageLength = ${pageName.length}, fullIndex = $fullIndex, fullLength = ${fullQualified.length}, score = $scoreAcc, consecutiveMatches = $consecutiveMatches" )
77
84
if searchIndex >= search.length then
85
+ println(" First IF" )
78
86
MatchResult (scoreAcc, page, acc)
79
- else if nameIndex >= pageName.length then
80
- MatchResult (0 , page, Set .empty)
87
+ else if nameIndex >= pageName.length || fullIndex >= fullQualified.length then
88
+ println(" Second IF" )
89
+ MatchResult (0 , page, Set .empty)
90
+ else if search.contains(" ." ) && fullQualified(fullIndex).toLower == search(searchIndex).toLower then
91
+ println(" Third IF" )
92
+ val score = (if consecutiveMatches > 0 then 1 else 0 ) + positionScores(nameIndex)
93
+ prematchPageAcc(nameIndex, searchIndex + 1 , fullIndex + 1 , acc + nameIndex, scoreAcc + score, consecutiveMatches + 1 )
81
94
else if pageName(nameIndex).toLower == search(searchIndex).toLower then
95
+ println(" Fourth IF" )
82
96
val score = (if consecutiveMatches > 0 then 1 else 0 ) + positionScores(nameIndex)
83
- prematchPageAcc(nameIndex + 1 , searchIndex + 1 , acc + nameIndex, scoreAcc + score, consecutiveMatches + 1 )
97
+ prematchPageAcc(nameIndex + 1 , searchIndex + 1 , fullIndex, acc + nameIndex, scoreAcc + score, consecutiveMatches + 1 )
84
98
else
85
- prematchPageAcc(nameIndex + 1 , searchIndex, acc, scoreAcc, 0 )
99
+ println(" Else" )
100
+ prematchPageAcc(nameIndex + 1 , searchIndex, fullIndex + 1 , acc, scoreAcc, 0 )
86
101
87
- val result = prematchPageAcc(0 , 0 , Set .empty, 0 , 0 )
102
+ println(" Calling prematchPageAcc" )
103
+ val result = prematchPageAcc(0 , 0 , 0 , Set .empty, 0 , 0 )
88
104
result.copy(score = result.score + kindScoreBonus(page.kind))
89
105
90
106
private def matchPage (prematched : MatchResult , nameSearch : String ): MatchResult =
0 commit comments