Skip to content
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
3 changes: 1 addition & 2 deletions dockerfiles/Dockerfile.dev.os
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ FROM python:3.10-slim
# update apt pkgs, and install build-essential for ciso8601
RUN apt-get update && \
apt-get -y upgrade && \
apt-get -y install build-essential && \
apt-get -y install build-essential git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN apt-get -y install git
# update certs used by Requests
ENV CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,38 @@

from typing import Any, Dict, List, Optional

from stac_fastapi.core.datetime_utils import datetime_to_str
from stac_fastapi.sfeos_helpers.mappings import Geometry
from stac_fastapi.types.rfc3339 import rfc3339_str_to_datetime

ES_MAX_URL_LENGTH = 4096


def is_numeric(val: str) -> bool:
"""Check if an input string value is numeric."""
try:
float(val)
return True
except ValueError:
return False


def process_ftq(q: str):
"""Process a date, numeric, or text free-text query."""
q = q.strip()
if not q:
return
try:
if d := rfc3339_str_to_datetime(q):
return datetime_to_str(d)
except ValueError:
pass
if is_numeric(q):
return q
else:
return f"({q}* OR {q.lower()}* OR {q.upper()}*)"


def apply_free_text_filter_shared(
search: Any, free_text_queries: Optional[List[str]]
) -> Any:
Expand All @@ -25,13 +52,17 @@ def apply_free_text_filter_shared(

Notes:
This function creates a query_string query that searches for the specified text strings
in all properties of the documents. The query strings are joined with OR operators.
in the entire document. The query strings are joined with OR operators.
"""
if free_text_queries is not None:
free_text_query_string = '" OR properties.\\*:"'.join(free_text_queries)
search = search.query(
"query_string", query=f'properties.\\*:"{free_text_query_string}"'
)
if free_text_queries:
processed_queries = [
process_ftq(q.strip()) for q in free_text_queries if q.strip()
]

if processed_queries:
free_text_query_string = " AND ".join(processed_queries)

search = search.query("query_string", query=free_text_query_string)

return search

Expand Down
Loading