Skip to content
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

fix: handle invalid lucene query term values gracefully #268

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def status_for_response(result: SearchResponse):
@app.post("/search")
def search(
response: Response, search_parameters: Annotated[PostSearchParameters, Body()]
):
) -> SearchResponse:
"""This is the main search endpoint.

It uses POST request to ensure privacy.
Expand Down
21 changes: 15 additions & 6 deletions app/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
from . import config
from ._types import (
DebugInfo,
ErrorSearchResponse,
QueryAnalysis,
SearchParameters,
SearchResponse,
SearchResponseDebug,
SearchResponseError,
SuccessSearchResponse,
)
from .charts import build_charts
from .exceptions import QueryCheckError
from .facets import build_facets
from .postprocessing import BaseResultProcessor, load_result_processor
from .query import build_elasticsearch_query_builder, build_search_query, execute_query
Expand Down Expand Up @@ -79,12 +82,18 @@ def search(
params.charts,
)
index_config = params.index_config
query = build_search_query(
params,
# ES query builder is generated from elasticsearch mapping and
# takes ~40ms to generate, build-it before hand to avoid this delay
es_query_builder=get_es_query_builder(params.valid_index_id),
)
try:
query = build_search_query(
params,
# ES query builder is generated from elasticsearch mapping and
# takes ~40ms to generate, build-it before hand to avoid this delay
es_query_builder=get_es_query_builder(params.valid_index_id),
)
except QueryCheckError as e:
return ErrorSearchResponse(
debug=SearchResponseDebug(),
errors=[SearchResponseError(title="QueryCheckError", description=str(e))],
)
(
logger.debug(
"Luqum query: %s\nElasticsearch query: %s",
Expand Down
Loading