@@ -24,7 +24,6 @@ def __init__(
2424 model : SentenceTransformer | None = None ,
2525 model_name : str = "sentence-transformers/paraphrase-MiniLM-L3-v2" ,
2626 ):
27- self ._inverted_index : dict [str , list [tuple [str , int ]]] = defaultdict (list )
2827 self ._words_per_doc : dict [str , int ] = defaultdict (int )
2928 self ._doc_id_to_url : dict [str , str ] = dict ()
3029 self ._doc_id_to_title : dict [str , str ] = dict ()
@@ -38,12 +37,10 @@ def __init__(
3837
3938 @property
4039 def total_docs (self ):
41- return len (self ._inverted_index )
40+ return len (self ._doc_id_to_url )
4241
4342 def insert (self , doc : Node ) -> None :
44- counts , total = self ._word_count (doc .text )
45- for word , count in counts .items ():
46- self ._inverted_index [word ].append ((doc .id , count ))
43+ _ , total = self ._word_count (doc .text )
4744 self ._words_per_doc [doc .id ] = total
4845 self ._doc_id_to_url [doc .id ] = doc .url
4946 self ._doc_id_to_title [doc .id ] = doc .title
@@ -65,21 +62,6 @@ def _word_count(self, text: str) -> dict[str, int]:
6562 total += 1
6663 return counts , total
6764
68- def _search (self , word : str ) -> list [tuple [str , int ]]:
69- result = self ._inverted_index .get (word )
70- return [] if result is None else result
71-
72- def search (self , word : str ) -> list [SearchResult ]:
73- return [
74- SearchResult (
75- id = kv [0 ],
76- url = self ._doc_id_to_url [kv [0 ]],
77- title = self ._doc_id_to_title [kv [0 ]],
78- score = None ,
79- )
80- for kv in self ._search (word )
81- ]
82-
8365 def num_words_in_doc (self , doc_id : str ) -> int :
8466 return self ._words_per_doc [doc_id ]
8567
0 commit comments