Skip to content

Add addtional parameters #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: fix-help-function
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions search.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
"""
import typer

from config import INDEX_NAME, SERVICE_URI, client
from config import INDEX_NAME, create_client
from helpers import log_titles
from typing import List

app = typer.Typer()


@app.command("match")
def search_match(field: str, query: str, operator: str = "or") -> None:
"""Perform search by relevance for certain field and query."""
Expand All @@ -34,10 +35,11 @@ def search_multi_match(fields: List[str], query: str) -> None:


@app.command("match-phrase")
def search_match_phrase(field, query):
def search_match_phrase(field, phrase, slop=0):
"""Search by match phrase for specific phrases in a field."""
typer.echo(f"Searching for {query} in the field {field}")
query_body = {"query": {"match_phrase": {field: {"query": query}}}}
typer.echo(f"Searching for {phrase} in the field {field}")
query_body = {"query": {"match_phrase": {field: {"query": phrase, "slop": slop}}}}
client = create_client()
resp = client.search(index=INDEX_NAME, body=query_body)
log_titles(resp)

Expand Down