86 lines
3.1 KiB
Python
86 lines
3.1 KiB
Python
#!/usr/bin/env python
|
||
"""
|
||
TestEventが検索でヒットしない問題のデバッグスクリプト
|
||
Deploy先でこのスクリプトを実行してください
|
||
|
||
実行方法:
|
||
docker compose exec app python debug_test_event.py
|
||
"""
|
||
|
||
import os
|
||
import django
|
||
|
||
# Django設定
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||
django.setup()
|
||
|
||
from rog.models import NewEvent2, Location2025
|
||
from django.db.models import Q
|
||
|
||
def debug_test_event():
|
||
print("=== TestEvent検索問題デバッグ ===")
|
||
|
||
# 1. 全イベント数
|
||
total_events = NewEvent2.objects.count()
|
||
print(f"総イベント数: {total_events}")
|
||
|
||
# 2. TestEventを含むイベントの検索(大文字小文字区別なし)
|
||
test_events = NewEvent2.objects.filter(event_name__icontains='testevent')
|
||
print(f"TestEventを含むイベント(大小文字無視): {test_events.count()}件")
|
||
|
||
for event in test_events:
|
||
print(f" - ID {event.id}: '{event.event_name}' (status: {event.status})")
|
||
|
||
# 3. Testを含むイベントの検索
|
||
test_partial = NewEvent2.objects.filter(event_name__icontains='test')
|
||
print(f"Testを含むイベント: {test_partial.count()}件")
|
||
|
||
for event in test_partial:
|
||
print(f" - ID {event.id}: '{event.event_name}' (status: {event.status})")
|
||
|
||
# 4. 最近作成されたイベント(上位10件)
|
||
print("\n=== 最近作成されたイベント(上位10件) ===")
|
||
recent_events = NewEvent2.objects.order_by('-id')[:10]
|
||
for event in recent_events:
|
||
print(f" - ID {event.id}: '{event.event_name}' (status: {event.status})")
|
||
|
||
# 5. 各種検索パターンテスト
|
||
print("\n=== 各種検索パターンテスト ===")
|
||
search_patterns = [
|
||
'TestEvent',
|
||
'testevent',
|
||
'Test',
|
||
'test',
|
||
'EVENT',
|
||
'event'
|
||
]
|
||
|
||
for pattern in search_patterns:
|
||
results = NewEvent2.objects.filter(event_name__icontains=pattern)
|
||
print(f"'{pattern}' を含むイベント: {results.count()}件")
|
||
if results.count() > 0 and results.count() <= 3:
|
||
for event in results:
|
||
print(f" - '{event.event_name}'")
|
||
|
||
# 6. ステータス別イベント数
|
||
print("\n=== ステータス別イベント数 ===")
|
||
from django.db.models import Count
|
||
status_counts = NewEvent2.objects.values('status').annotate(count=Count('id')).order_by('status')
|
||
for item in status_counts:
|
||
print(f" {item['status']}: {item['count']}件")
|
||
|
||
# 7. 特定の文字列での完全一致検索
|
||
print("\n=== 完全一致検索テスト ===")
|
||
exact_match = NewEvent2.objects.filter(event_name='TestEvent')
|
||
print(f"'TestEvent'完全一致: {exact_match.count()}件")
|
||
|
||
if exact_match.exists():
|
||
for event in exact_match:
|
||
print(f" - ID {event.id}: '{event.event_name}' (status: {event.status})")
|
||
# 関連するLocation2025も確認
|
||
cp_count = Location2025.objects.filter(event=event).count()
|
||
print(f" 関連チェックポイント: {cp_count}件")
|
||
|
||
if __name__ == '__main__':
|
||
debug_test_event()
|