@@ -2,6 +2,10 @@ import { Task, TasksByProject } from './models/TasksByProject';
22import { Suggestion , SuggestionsByProject } from './models/TasksTypes' ;
33import TreeModelHelper from '../../helpers/TreeModelHelper' ;
44
5+ const MIN_FREQUENCY = 3 ;
6+ const MAX_TEXT_SIZE = 99 ;
7+ const MAX_COUNT = 10 ;
8+
59export function findSuggestionsByProject (
610 tasksByProject : TasksByProject
711) : SuggestionsByProject {
@@ -17,16 +21,20 @@ export function findSuggestionsByProject(
1721
1822function prepareSuggestions ( suggestions : Suggestion [ ] ) {
1923 return suggestions
20- . filter ( ( item ) => item . frequency > 1 )
21- . sort ( ( a , b ) => a . frequency - b . frequency ) ;
24+ . filter ( ( item ) => item . frequency >= MIN_FREQUENCY )
25+ . sort ( ( a , b ) => b . frequency - a . frequency )
26+ . slice ( 0 , MAX_COUNT ) ;
2227}
2328
2429function findSuggestions ( tasks : Task [ ] ) {
2530 const suggestions : Record < number , Suggestion > = { } ;
2631
2732 TreeModelHelper . iterate ( tasks , ( task ) => {
2833 const text = task . title ;
29- // TODO ignore long strings?
34+ // ignore long strings
35+ if ( text . length > MAX_TEXT_SIZE ) {
36+ return ;
37+ }
3038 const hash = hashCode ( text ) ;
3139 if ( hash in suggestions ) {
3240 suggestions [ hash ] . frequency ++ ;
0 commit comments