33import java .util .HashMap ;
44
55public class SearchEngine {
6- public HashMap <String , Double > documentsOrder ;
6+ static HashMap <String , HashMap < String , Double >> documentsOrder = new HashMap < String , HashMap < String , Double >>() ;
77
88/**
99 *
@@ -22,12 +22,36 @@ public static void searchByQuery(String query, HashMap<String, HashMap<String[],
2222values = documents .get (document ).get (insideWord );
2323for (int i = 0 ; i <=words .length -1 ;i ++) {
2424if (words [i ].equals (word )) {
25- System .out .println ("Hey encontramos algo parecidooooo!" );
25+ System .out .println ("Hey encontramos algo parecidooooo! " +document +" " + words [i ]+" " +values [i ]);
26+ verifyWordInMap (document , words [i ], values [i ]);
2627}
2728}
2829}
2930
3031}
3132}
3233}
34+
35+ public static void verifyWordInMap (String document , String word , Double value ) {
36+ if (documentsOrder .containsKey (document )) {
37+ if (!documentsOrder .get (document ).containsKey (word )) {
38+ addInnerWordToDocumentInsideMap (document ,word ,value );
39+ }else {
40+ System .out .println ("Ya estaba" );
41+ }
42+ }
43+ else {
44+ System .out .println ("No estaba" );
45+ addWordInMap (document ,word ,value );
46+ }
47+ }
48+ public static void addWordInMap (String document , String word , Double value ) {
49+ HashMap <String , Double > innerMap = new HashMap <String , Double >();
50+ innerMap .put (word ,value );
51+ documentsOrder .put (document ,innerMap );
52+ }
53+ public static void addInnerWordToDocumentInsideMap (String document ,String word , Double value ) {
54+ documentsOrder .get (document ).put (word ,value );
55+ }
56+
3357}
0 commit comments