feat: Add force_hierarchical mode to prevent fallback

## Changes

Allow users to force hierarchical search mode without fallback to simple
search, enabling testing of hierarchical UI even when 0 summaries are found.

**Backend (flask_app.py):**
- Added `force_hierarchical` parameter to `hierarchical_search()`
- When True, never fallback to simple search (return empty hierarchical result)
- Added `fallback_reason` field to explain why no results
- Pass `force_hierarchical=True` when `force_mode == "hierarchical"`
- Applied to all fallback points:
  - No Weaviate client
  - No summaries found in Stage 1
  - No sections after author/work filtering
  - Exception during search

**Frontend (templates/search.html):**
- Display warning message when `fallback_reason` exists
- Yellow alert box with explanation and suggestions
- Works even when `results_data.results` is empty

## Usage

1. Select "🌳 Hiérarchique (2-étapes)" in Mode dropdown
2. Enter any query (even if no matching summaries)
3. See hierarchical UI with warning instead of fallback

## Example

Query: "Qu'est-ce que la justice ?" (not in Peirce corpus)
- Mode forced: Hierarchical
- Result: 0 sections, warning displayed
- No silent fallback to simple search

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-01 14:24:44 +01:00
parent 0dcccc93d1
commit f6000de230
2 changed files with 89 additions and 29 deletions

View File

@@ -130,7 +130,7 @@
{% if query %}
<div class="ornament">·</div>
{% if results_data and results_data.results %}
{% if results_data %}
<!-- Mode indicator and stats -->
<div class="mb-3" style="display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;">
<div>
@@ -160,6 +160,17 @@
{% endif %}
</div>
<!-- Fallback reason warning (when forced hierarchical but no results) -->
{% if results_data.fallback_reason %}
<div class="alert" style="background-color: #fff3cd; border: 1px solid #ffc107; color: #856404; padding: 1rem; border-radius: 4px; margin-bottom: 1rem;">
<strong>⚠️ Mode hiérarchique forcé :</strong> {{ results_data.fallback_reason }}
<br>
<small>💡 Essayez une requête sur un sujet présent dans le corpus (ex: "croyance", "signe", "inférence") ou basculez en mode Auto-détection.</small>
</div>
{% endif %}
{% if results_data.results %}
<!-- Hierarchical display -->
{% if results_data.mode == "hierarchical" and results_data.sections %}
{% for section in results_data.sections %}