# 💡 SOLUTION: Disable Filesystem Discovery for Mapped Documents

## 🚨 **Root Cause Identified**

When `CORRECT_FILE_MAPPING` is applied:
1. ✅ Correct single page URL is set (`879dcd53...275.bin`)
2. ❌ Filesystem discovery finds 195 pages near that file
3. ❌ Those 195 pages belong to a DIFFERENT document in same directory
4. ❌ Result: BP102 shows pages from wrong document

---

## 🔧 **Quick Fix: Disable Filesystem Discovery for Mapped Documents**

For documents with `CORRECT_FILE_MAPPING`, we should:
- ✅ Use the mapped URL for single-page documents (History Card)
- ❌ DISABLE filesystem discovery for multi-page documents (Property File)
- ⚠️ This means we'll only get 1 page instead of all pages

### **Trade-off:**
- **Option A**: Get 1 correct page (better than 195 wrong pages)
- **Option B**: Find ALL correct page URLs (requires transaction analysis)

---

## 🎯 **RECOMMENDED: Option A (Quick Fix)**

Disable filesystem discovery when mapping is applied:

```python
# In aumentum_browser_service.py, around line 941
if page_count and page_count > len(db_images) and len(db_images) > 0:
    # Skip filesystem discovery if mapping was applied
    if mapping_applied:
        print(f"   ⚠️  Skipping filesystem discovery (mapping applied)")
        print(f"   Will use only the mapped file (may be incomplete for multi-page docs)")
    else:
        print(f"🔍 Document ID {doc_id}: Expected {page_count} pages, found {len(db_images)} in DB")
        print(f"   Using filesystem-based discovery...")
        
        discovered_urls = self._discover_pages_by_filesystem(...)
```

This way:
- ✅ BP102 History Card (1-2 pages) → Gets correct content
- ⚠️ BP102 Property File (195 pages) → Gets only 1 page (but it's the correct document)

---

## 🚀 **BETTER SOLUTION: Option B (Transaction-Based Page Discovery)**

Use transaction information to find ALL pages that belong to a document:

1. Query `lr_transaction_document` to find transaction for this document
2. Find all documents in that transaction
3. Get Alfresco nodes for those documents
4. Filter pages that belong to THIS specific document

This is more complex but gives complete multi-page documents.

---

## ⚡ **Which Do You Want?**

**Option A (Quick):**
- Implement in 5 minutes
- Works immediately
- Only 1 page per mapped document
- Good enough for verification

**Option B (Complete):**
- Implement in 30-60 minutes
- All pages included
- Requires transaction table analysis
- Production-quality solution

---

Let me know which you prefer, or I can implement Option A now!

