# -*- coding: utf-8 -*- import urllib.request, json B = 'http://127.0.0.1:8012' def get(path): try: r = urllib.request.urlopen(B + path, timeout=20) return r.status, r.read().decode('utf-8') except urllib.error.HTTPError as e: return e.code, e.read().decode('utf-8') # 1) FTS 搜索:代位权(>=3字,应 fts=true,只在库题) s, b = get('/api/v1/question/search_fts?keyword=%E4%BB%A3%E4%BD%8D%E6%9D%83&subject=%E4%B8%80%E9%80%A0%E7%AE%A1%E7%90%86&page=1&page_size=5') print('== FTS search 代位权 [一造管理] ==', s) d = json.loads(b) print('fts flag =', d['data'].get('fts'), ' total =', d['data']['total']) for it in d['data']['list'][:5]: print(' id=', it.get('id'), 'q_type=', it.get('q_type'), 'title=', str(it.get('title'))[:34]) # 2) FTS 科目隔离:用一造水利案例科目搜同一关键词,应 0 或极少 s, b = get('/api/v1/question/search_fts?keyword=%E4%BB%A3%E4%BD%8D%E6%9D%83&subject=%E4%B8%80%E9%80%A0%E6%B0%B4%E5%88%A9%E6%A1%88%E4%BE%8B') d = json.loads(b) print('== FTS 科目隔离[水利案例] 代位权 == total =', d['data']['total'], '(应=0)') # 3) LIKE 兜底:2字 s, b = get('/api/v1/question/search_fts?keyword=%E7%AE%A1%E7%90%86&page_size=3') d = json.loads(b) print('== LIKE兜底 2字 管理 == fts=', d['data'].get('fts'), 'total=', d['data']['total']) # 4) export_editable json(小样本) s, b = get('/api/v1/question/export_editable?subject=%E4%B8%80%E9%80%A0%E7%AE%A1%E7%90%86&export_format=json') d = json.loads(b) print('== export_editable json == status', s, 'total=', d.get('total'), 'cols=', d.get('columns')) print(' row0 keys sample:', {k: (str(v)[:20]) for k, v in list(d['rows'][0].items())[:6]})