diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..aae3576 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +fmt: + pdm fmt + +test: fmt + pdm test + +build: test + pdm build diff --git a/tinysearch/document.py b/tinysearch/document.py index a7347d5..407da6e 100644 --- a/tinysearch/document.py +++ b/tinysearch/document.py @@ -38,7 +38,10 @@ def __init__(self, original: str): self.tokens = self.analyze() def __str__(self): - return f'"{self.original}"' + return f"Document['{self.original}']" + + def __repr__(self): + return self.__str__() def analyze(self) -> Counter: """Parses the original text into a list of tokens.""" diff --git a/tinysearch/index.py b/tinysearch/index.py index 1a83a82..ac59847 100644 --- a/tinysearch/index.py +++ b/tinysearch/index.py @@ -22,6 +22,12 @@ class Index: def __init__(self, docs: List[str]) -> None: self.docs = self.process_docs(docs) + def __str__(self): + return f"Index[docs={len(self.docs)}]" + + def __repr__(self): + return self.__str__() + def process_docs(self, docs: List[str]) -> List[Document]: processed = [] for doc in docs: diff --git a/tinysearch/search.py b/tinysearch/search.py index fa8dee5..59110ce 100644 --- a/tinysearch/search.py +++ b/tinysearch/search.py @@ -54,6 +54,9 @@ def __init__(self): def __str__(self): return str(self.results) + def __repr__(self): + return self.__str__() + def append(self, result: Result) -> None: self.results.append(result) if result.score > 0.0: @@ -78,6 +81,12 @@ def __init__(self, docs: List[str], query: str) -> None: self.results = Results() self.search() + def __str__(self): + return f"Search[query='{self.query}', matches={self.results.count}]" + + def __repr__(self): + return self.__str__() + def search(self) -> Results: self.score_docs(self.query)