Spaces:
Running
Running
Commit
Β·
a801174
1
Parent(s):
07f1abd
Fixed basic search and advanced search switching
Browse files- src/callbacks.py +63 -15
- src/components.py +9 -4
src/callbacks.py
CHANGED
|
@@ -210,7 +210,9 @@ def register_callbacks(app, search_service: SearchService):
|
|
| 210 |
Output("current-search-params", "data")],
|
| 211 |
[Input("search-button", "n_clicks"),
|
| 212 |
Input("search-input", "n_submit"),
|
| 213 |
-
Input("search-button-advanced", "n_clicks")
|
|
|
|
|
|
|
| 214 |
[State("search-input", "value"),
|
| 215 |
State("search-input-advanced", "value"),
|
| 216 |
State("rmag-slider", "value"),
|
|
@@ -226,14 +228,22 @@ def register_callbacks(app, search_service: SearchService):
|
|
| 226 |
State({"type": "vector-operation", "index": dash.dependencies.ALL}, "value")],
|
| 227 |
prevent_initial_call=True
|
| 228 |
)
|
| 229 |
-
def perform_search(n_clicks_basic,
|
|
|
|
| 230 |
rmag_range, advanced_style, main_operation, main_query_type,
|
| 231 |
main_ra, main_dec,
|
| 232 |
additional_query_types, additional_text_values, additional_ra_values,
|
| 233 |
additional_dec_values, additional_operations):
|
| 234 |
"""Perform text search or advanced search based on mode."""
|
| 235 |
-
# Check
|
| 236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
|
| 238 |
# If advanced mode is active, perform advanced search
|
| 239 |
if is_advanced_mode:
|
|
@@ -882,7 +892,8 @@ def register_callbacks(app, search_service: SearchService):
|
|
| 882 |
Output("basic-search-bar", "style", allow_duplicate=True),
|
| 883 |
Output("vector-arrow", "className", allow_duplicate=True),
|
| 884 |
Output("url-search-trigger", "data", allow_duplicate=True),
|
| 885 |
-
Output("pending-expand-galaxy", "data")
|
|
|
|
| 886 |
Input("url", "search"),
|
| 887 |
prevent_initial_call=True
|
| 888 |
)
|
|
@@ -907,10 +918,11 @@ def register_callbacks(app, search_service: SearchService):
|
|
| 907 |
dash.no_update, # basic-search-bar style
|
| 908 |
dash.no_update, # vector-arrow
|
| 909 |
dash.no_update, # url-search-trigger
|
| 910 |
-
None # pending-expand-galaxy
|
|
|
|
| 911 |
)
|
| 912 |
|
| 913 |
-
#
|
| 914 |
text_queries = state.get('text_queries', [])
|
| 915 |
text_weights = state.get('text_weights', [])
|
| 916 |
image_queries = state.get('image_queries', [])
|
|
@@ -919,7 +931,33 @@ def register_callbacks(app, search_service: SearchService):
|
|
| 919 |
rmag_max = state.get('rmag_max', 20.0)
|
| 920 |
expand_galaxy = state.get('expand_galaxy')
|
| 921 |
|
| 922 |
-
# Determine
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 923 |
main_text = ""
|
| 924 |
main_operation = "+"
|
| 925 |
main_query_type = "text"
|
|
@@ -980,20 +1018,30 @@ def register_callbacks(app, search_service: SearchService):
|
|
| 980 |
{"display": "none"}, # basic-search-bar (hide)
|
| 981 |
"fas fa-chevron-up me-2", # vector-arrow (up arrow for advanced mode)
|
| 982 |
1, # url-search-trigger (trigger search)
|
| 983 |
-
expand_galaxy # pending-expand-galaxy
|
|
|
|
| 984 |
)
|
| 985 |
|
| 986 |
@app.callback(
|
| 987 |
-
Output("search-button
|
|
|
|
| 988 |
Input("url-search-trigger", "data"),
|
| 989 |
-
State("search-button
|
|
|
|
|
|
|
| 990 |
prevent_initial_call=True
|
| 991 |
)
|
| 992 |
-
def trigger_search_from_url(trigger,
|
| 993 |
-
"""Click search button after URL state is restored."""
|
| 994 |
if trigger:
|
| 995 |
-
|
| 996 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 997 |
|
| 998 |
@app.callback(
|
| 999 |
Output("url", "search", allow_duplicate=True),
|
|
|
|
| 210 |
Output("current-search-params", "data")],
|
| 211 |
[Input("search-button", "n_clicks"),
|
| 212 |
Input("search-input", "n_submit"),
|
| 213 |
+
Input("search-button-advanced", "n_clicks"),
|
| 214 |
+
Input("search-input-advanced", "n_submit"),
|
| 215 |
+
Input({"type": "vector-text", "index": dash.dependencies.ALL}, "n_submit")],
|
| 216 |
[State("search-input", "value"),
|
| 217 |
State("search-input-advanced", "value"),
|
| 218 |
State("rmag-slider", "value"),
|
|
|
|
| 228 |
State({"type": "vector-operation", "index": dash.dependencies.ALL}, "value")],
|
| 229 |
prevent_initial_call=True
|
| 230 |
)
|
| 231 |
+
def perform_search(n_clicks_basic, n_submit_basic, n_clicks_advanced, n_submit_advanced, n_submit_vector_texts,
|
| 232 |
+
query_basic, query_advanced,
|
| 233 |
rmag_range, advanced_style, main_operation, main_query_type,
|
| 234 |
main_ra, main_dec,
|
| 235 |
additional_query_types, additional_text_values, additional_ra_values,
|
| 236 |
additional_dec_values, additional_operations):
|
| 237 |
"""Perform text search or advanced search based on mode."""
|
| 238 |
+
# Check which input triggered the callback
|
| 239 |
+
ctx = callback_context
|
| 240 |
+
if not ctx.triggered:
|
| 241 |
+
return dash.no_update, dash.no_update, dash.no_update, dash.no_update, dash.no_update, dash.no_update
|
| 242 |
+
|
| 243 |
+
trigger_id = ctx.triggered[0]["prop_id"].split(".")[0]
|
| 244 |
+
|
| 245 |
+
# Determine if advanced mode based on which button/input triggered the search
|
| 246 |
+
is_advanced_mode = trigger_id in ["search-button-advanced", "search-input-advanced"] or advanced_style.get("display") == "block"
|
| 247 |
|
| 248 |
# If advanced mode is active, perform advanced search
|
| 249 |
if is_advanced_mode:
|
|
|
|
| 892 |
Output("basic-search-bar", "style", allow_duplicate=True),
|
| 893 |
Output("vector-arrow", "className", allow_duplicate=True),
|
| 894 |
Output("url-search-trigger", "data", allow_duplicate=True),
|
| 895 |
+
Output("pending-expand-galaxy", "data"),
|
| 896 |
+
Output("search-input", "value", allow_duplicate=True)],
|
| 897 |
Input("url", "search"),
|
| 898 |
prevent_initial_call=True
|
| 899 |
)
|
|
|
|
| 918 |
dash.no_update, # basic-search-bar style
|
| 919 |
dash.no_update, # vector-arrow
|
| 920 |
dash.no_update, # url-search-trigger
|
| 921 |
+
None, # pending-expand-galaxy
|
| 922 |
+
dash.no_update # search-input
|
| 923 |
)
|
| 924 |
|
| 925 |
+
# Parse state
|
| 926 |
text_queries = state.get('text_queries', [])
|
| 927 |
text_weights = state.get('text_weights', [])
|
| 928 |
image_queries = state.get('image_queries', [])
|
|
|
|
| 931 |
rmag_max = state.get('rmag_max', 20.0)
|
| 932 |
expand_galaxy = state.get('expand_galaxy')
|
| 933 |
|
| 934 |
+
# Determine if this is a basic search (single text query with weight +1) or advanced search
|
| 935 |
+
is_basic_search = (
|
| 936 |
+
len(text_queries) == 1 and
|
| 937 |
+
len(text_weights) == 1 and
|
| 938 |
+
text_weights[0] == 1.0 and
|
| 939 |
+
len(image_queries) == 0
|
| 940 |
+
)
|
| 941 |
+
|
| 942 |
+
if is_basic_search:
|
| 943 |
+
# For basic search, just populate the basic search input and stay in basic mode
|
| 944 |
+
return (
|
| 945 |
+
dash.no_update, # search-input-advanced
|
| 946 |
+
dash.no_update, # main-vector-operation
|
| 947 |
+
dash.no_update, # main-query-type
|
| 948 |
+
dash.no_update, # main-vector-ra
|
| 949 |
+
dash.no_update, # main-vector-dec
|
| 950 |
+
dash.no_update, # vector-inputs
|
| 951 |
+
[rmag_min, rmag_max], # rmag-slider
|
| 952 |
+
{"display": "none"}, # advanced-search-interface (hide)
|
| 953 |
+
{"display": "block"}, # basic-search-bar (show)
|
| 954 |
+
"fas fa-chevron-down me-2", # vector-arrow (down arrow for basic mode)
|
| 955 |
+
1, # url-search-trigger (trigger search)
|
| 956 |
+
expand_galaxy, # pending-expand-galaxy
|
| 957 |
+
text_queries[0] if text_queries else "" # search-input (populate basic search)
|
| 958 |
+
)
|
| 959 |
+
|
| 960 |
+
# For advanced search, populate all the advanced fields
|
| 961 |
main_text = ""
|
| 962 |
main_operation = "+"
|
| 963 |
main_query_type = "text"
|
|
|
|
| 1018 |
{"display": "none"}, # basic-search-bar (hide)
|
| 1019 |
"fas fa-chevron-up me-2", # vector-arrow (up arrow for advanced mode)
|
| 1020 |
1, # url-search-trigger (trigger search)
|
| 1021 |
+
expand_galaxy, # pending-expand-galaxy
|
| 1022 |
+
dash.no_update # search-input (don't update in advanced mode)
|
| 1023 |
)
|
| 1024 |
|
| 1025 |
@app.callback(
|
| 1026 |
+
[Output("search-button", "n_clicks", allow_duplicate=True),
|
| 1027 |
+
Output("search-button-advanced", "n_clicks", allow_duplicate=True)],
|
| 1028 |
Input("url-search-trigger", "data"),
|
| 1029 |
+
[State("search-button", "n_clicks"),
|
| 1030 |
+
State("search-button-advanced", "n_clicks"),
|
| 1031 |
+
State("basic-search-bar", "style")],
|
| 1032 |
prevent_initial_call=True
|
| 1033 |
)
|
| 1034 |
+
def trigger_search_from_url(trigger, current_basic_clicks, current_advanced_clicks, basic_style):
|
| 1035 |
+
"""Click appropriate search button after URL state is restored."""
|
| 1036 |
if trigger:
|
| 1037 |
+
# Determine which mode we're in based on which search bar is visible
|
| 1038 |
+
is_basic_mode = basic_style.get("display") == "block"
|
| 1039 |
+
|
| 1040 |
+
if is_basic_mode:
|
| 1041 |
+
return (current_basic_clicks or 0) + 1, dash.no_update
|
| 1042 |
+
else:
|
| 1043 |
+
return dash.no_update, (current_advanced_clicks or 0) + 1
|
| 1044 |
+
return dash.no_update, dash.no_update
|
| 1045 |
|
| 1046 |
@app.callback(
|
| 1047 |
Output("url", "search", allow_duplicate=True),
|
src/components.py
CHANGED
|
@@ -627,10 +627,13 @@ def create_search_container():
|
|
| 627 |
dbc.Col([
|
| 628 |
# Text input (shown when type is "text")
|
| 629 |
html.Div([
|
| 630 |
-
|
| 631 |
id="search-input-advanced",
|
| 632 |
placeholder="Enter text query...",
|
| 633 |
-
type="text"
|
|
|
|
|
|
|
|
|
|
| 634 |
)
|
| 635 |
], id="main-text-input-container", style={"display": "block"}),
|
| 636 |
# Image inputs (shown when type is "image")
|
|
@@ -761,11 +764,13 @@ def create_vector_input_row(index: int, query_type: str = "text", ra: float = No
|
|
| 761 |
dbc.Col([
|
| 762 |
# Text input (shown when type is "text")
|
| 763 |
html.Div([
|
| 764 |
-
|
| 765 |
id={"type": "vector-text", "index": index},
|
| 766 |
placeholder="Enter text query...",
|
| 767 |
type="text",
|
| 768 |
-
value=text_value
|
|
|
|
|
|
|
| 769 |
)
|
| 770 |
], id={"type": "text-input-container", "index": index}, style=text_display),
|
| 771 |
# Image inputs (shown when type is "image")
|
|
|
|
| 627 |
dbc.Col([
|
| 628 |
# Text input (shown when type is "text")
|
| 629 |
html.Div([
|
| 630 |
+
dcc.Input(
|
| 631 |
id="search-input-advanced",
|
| 632 |
placeholder="Enter text query...",
|
| 633 |
+
type="text",
|
| 634 |
+
value="",
|
| 635 |
+
n_submit=0,
|
| 636 |
+
className="form-control"
|
| 637 |
)
|
| 638 |
], id="main-text-input-container", style={"display": "block"}),
|
| 639 |
# Image inputs (shown when type is "image")
|
|
|
|
| 764 |
dbc.Col([
|
| 765 |
# Text input (shown when type is "text")
|
| 766 |
html.Div([
|
| 767 |
+
dcc.Input(
|
| 768 |
id={"type": "vector-text", "index": index},
|
| 769 |
placeholder="Enter text query...",
|
| 770 |
type="text",
|
| 771 |
+
value=text_value,
|
| 772 |
+
n_submit=0,
|
| 773 |
+
className="form-control"
|
| 774 |
)
|
| 775 |
], id={"type": "text-input-container", "index": index}, style=text_display),
|
| 776 |
# Image inputs (shown when type is "image")
|