Skip to content

Commit

Permalink
feat: limiter les resultats
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Jul 6, 2024
1 parent 9ee34a3 commit 143c822
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 5 additions & 2 deletions alexi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def index_main(args: argparse.Namespace):

def search_main(args: argparse.Namespace):
"""Lancer une recherche sur l'index"""
search(args.indexdir, args.query)
search(args.indexdir, args.query, args.nresults)


def make_argparse() -> argparse.ArgumentParser:
Expand Down Expand Up @@ -210,7 +210,10 @@ def make_argparse() -> argparse.ArgumentParser:
"--indexdir",
help="Repertoire source pour l'index",
type=Path,
default="indexdir",
default="export/_idx",
)
search.add_argument(
"-n", "--nresults", help="Nombre de résultats affichés", type=int, default=10
)
search.add_argument("query", help="Requête", nargs="+")
search.set_defaults(func=search_main)
Expand Down
7 changes: 4 additions & 3 deletions alexi/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
get_nltk_builder(["fr"])


def search(indexdir: Path, terms: List[str]) -> None:
def search(indexdir: Path, terms: List[str], nresults: int) -> None:
with open(indexdir / "index.json", "rt", encoding="utf-8") as infh:
index = Index.load(json.load(infh))
index.pipeline.add(unifold)
results = index.search(" ".join(terms))
for r in results:
for idx, r in enumerate(results):
if idx == nresults:
break
print(r)
print(r["match_data"].metadata)

0 comments on commit 143c822

Please sign in to comment.