runtime.diff 6.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --- sealed-r3/server/voc-library/retrieval.py
  2. +++ ksf-unified-runtime-hotfix-20261109-r1/server/voc-library/retrieval.py
  3. @@ -170,6 +170,11 @@
  4. 'fields':{k:{'type':typ,'operators':['eq','in','exists']+(['min','max'] if typ in ('number','date') else []),'unit':'CNY分' if k=='priceMinor' else 'g' if k=='netWeightG' else '原文日历日期;时区未统一' if typ=='date' else None} for k,(_,typ) in FIELDS.items()},
  5. 'productSorts':{'reviews_asc':'已收录评论从少到多(含默认及待核)','reviews_desc':'已收录评论从多到少(含默认及待核)',
  6. 'price_asc':'最低历史观察价从低到高,未知置后','price_desc':'最低历史观察价从高到低,未知置后'},
  7. + 'aggregation':{'entityParameter':'entities','groupingParameter':'groupBy',
  8. + 'facetsDefaultFields':['platform','category'],
  9. + 'productFacetsDefaultFields':['platform','brand','category'],
  10. + 'socialBrandGrouping':'explicit brand grouping with social entities is rejected; mentions are not product ownership',
  11. + 'facetsExamples':{'allEntities':{},'productBrands':{'entities':['products'],'groupBy':['brand'],'limit':20}}},
  12. 'taxonomy':tax,'concepts':CONCEPTS,
  13. 'relationships':['products.id → reviews/prices/specs/rankings/coverage.product_id','documents.id → clauses.document_id','all.source_record_id → source_records.id → source_links/assets/collection_requests','social品牌仅为提及关系,不能推为商品归属'],
  14. 'questionRoutes':[
  15. @@ -383,7 +388,8 @@
  16. def aggregate(c,request,facets=False):
  17. where,values,effective=prepare(c,request)
  18. - fields=request.get('groupBy',['platform','brand','category'] if facets else ['platform'])
  19. + defaults=(['platform','category'] if 'social' in effective['entities'] else ['platform','brand','category']) if facets else ['platform']
  20. + fields=request.get('groupBy',defaults)
  21. require(isinstance(fields,list) and 1<=len(fields)<=4 and all(isinstance(f,str) and f in FIELDS for f in fields) and len(fields)==len(set(fields)),'INVALID_GROUP_BY')
  22. require(not ('brand' in fields and 'social' in effective['entities']),'SOCIAL_BRAND_IS_MENTION_NOT_GROUPABLE_OWNERSHIP')
  23. limit=request.get('limit',50);require(type(limit) is int and 1<=limit<=100,'INVALID_LIMIT')
  24. --- sealed-r3/server/voc-library/update_library.py
  25. +++ ksf-unified-runtime-hotfix-20261109-r1/server/voc-library/update_library.py
  26. @@ -138,11 +138,22 @@
  27. entity='products' if row['entity_type']=='product' else 'reviews'
  28. candidate=c.execute('SELECT incoming_source_record_id,selected_source_record_id FROM merge_decisions WHERE entity=? AND record_id=? AND batch_sha256=? AND decision=?',
  29. (entity,row['entity_id'],im['archive_sha256'],'kept_existing')).fetchone()
  30. - if candidate:
  31. + if candidate and candidate['incoming_source_record_id']!=candidate['selected_source_record_id']:
  32. row['detail']=canonical({'scope':'incoming_candidate_not_current_row',
  33. 'candidateSourceRecordId':candidate[0],'selectedSourceRecordId':candidate[1],'originalDetail':row['detail']})
  34. columns=list(row)
  35. old=c.execute('SELECT * FROM '+table+' WHERE '+' AND '.join(k+'=?' for k in pk),[row[k] for k in pk]).fetchone()
  36. + if table=='source_records':
  37. + # Asset remapping may resolve to a previously imported archive.
  38. + # Rebuilt importer generations must reuse its exact source locator.
  39. + located=c.execute('SELECT * FROM source_records WHERE asset_path=? AND line_number=?',
  40. + (row['asset_path'],row['line_number'])).fetchone()
  41. + if located:
  42. + voc_db.require(all(located[k]==value for k,value in row.items() if k!='id'),
  43. + 'SOURCE_LOCATOR_CONFLICT')
  44. + mapping[original['id']]=located['id']
  45. + delta['duplicate'][table]=delta['duplicate'].get(table,0)+1
  46. + continue
  47. if table=='batches' and old and old['archive_sha256']==row['archive_sha256']:
  48. mapping[original['id']]=old['id'];delta['duplicate'][table]=delta['duplicate'].get(table,0)+1;continue
  49. # The same timestamped price observation may be re-exported under a new source locator.
  50. @@ -191,6 +202,17 @@
  51. if old and table not in STABLE:
  52. voc_db.require(len(pk)==1 and pk[0] in ('id','path','asset_path'),'CONFLICTING_RELATION:'+table)
  53. col=pk[0]
  54. + if col=='id':
  55. + # Related evidence from older importer generations may already
  56. + # have a namespaced ID. Reuse it only when every fact and FK agrees.
  57. + facts=[k for k in columns if k!=col]
  58. + equivalent=c.execute('SELECT '+col+' FROM '+table+' WHERE '+
  59. + ' AND '.join(k+' IS ?' for k in facts)+' ORDER BY '+col+' LIMIT 1',
  60. + [row[k] for k in facts]).fetchone()
  61. + if equivalent:
  62. + mapping[original[col]]=equivalent[col]
  63. + delta['duplicate'][table]=delta['duplicate'].get(table,0)+1
  64. + continue
  65. if table=='assets':row[col]='batches/'+im['archive_sha256'][:16]+'/'+row[col]
  66. elif table=='collection_requests':raise ValueError('CONFLICTING_COLLECTION_REQUEST')
  67. else:row[col]=hashlib.sha256((im['generation']+':'+str(original[col])).encode()).hexdigest()