|
|
@@ -0,0 +1,68 @@
|
|
|
+--- sealed-r3/server/voc-library/retrieval.py
|
|
|
++++ ksf-unified-runtime-hotfix-20261109-r1/server/voc-library/retrieval.py
|
|
|
+@@ -170,6 +170,11 @@
|
|
|
+ '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()},
|
|
|
+ 'productSorts':{'reviews_asc':'已收录评论从少到多(含默认及待核)','reviews_desc':'已收录评论从多到少(含默认及待核)',
|
|
|
+ 'price_asc':'最低历史观察价从低到高,未知置后','price_desc':'最低历史观察价从高到低,未知置后'},
|
|
|
++ 'aggregation':{'entityParameter':'entities','groupingParameter':'groupBy',
|
|
|
++ 'facetsDefaultFields':['platform','category'],
|
|
|
++ 'productFacetsDefaultFields':['platform','brand','category'],
|
|
|
++ 'socialBrandGrouping':'explicit brand grouping with social entities is rejected; mentions are not product ownership',
|
|
|
++ 'facetsExamples':{'allEntities':{},'productBrands':{'entities':['products'],'groupBy':['brand'],'limit':20}}},
|
|
|
+ 'taxonomy':tax,'concepts':CONCEPTS,
|
|
|
+ '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品牌仅为提及关系,不能推为商品归属'],
|
|
|
+ 'questionRoutes':[
|
|
|
+@@ -383,7 +388,8 @@
|
|
|
+
|
|
|
+ def aggregate(c,request,facets=False):
|
|
|
+ where,values,effective=prepare(c,request)
|
|
|
+- fields=request.get('groupBy',['platform','brand','category'] if facets else ['platform'])
|
|
|
++ defaults=(['platform','category'] if 'social' in effective['entities'] else ['platform','brand','category']) if facets else ['platform']
|
|
|
++ fields=request.get('groupBy',defaults)
|
|
|
+ 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')
|
|
|
+ require(not ('brand' in fields and 'social' in effective['entities']),'SOCIAL_BRAND_IS_MENTION_NOT_GROUPABLE_OWNERSHIP')
|
|
|
+ limit=request.get('limit',50);require(type(limit) is int and 1<=limit<=100,'INVALID_LIMIT')
|
|
|
+--- sealed-r3/server/voc-library/update_library.py
|
|
|
++++ ksf-unified-runtime-hotfix-20261109-r1/server/voc-library/update_library.py
|
|
|
+@@ -138,11 +138,22 @@
|
|
|
+ entity='products' if row['entity_type']=='product' else 'reviews'
|
|
|
+ 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=?',
|
|
|
+ (entity,row['entity_id'],im['archive_sha256'],'kept_existing')).fetchone()
|
|
|
+- if candidate:
|
|
|
++ if candidate and candidate['incoming_source_record_id']!=candidate['selected_source_record_id']:
|
|
|
+ row['detail']=canonical({'scope':'incoming_candidate_not_current_row',
|
|
|
+ 'candidateSourceRecordId':candidate[0],'selectedSourceRecordId':candidate[1],'originalDetail':row['detail']})
|
|
|
+ columns=list(row)
|
|
|
+ old=c.execute('SELECT * FROM '+table+' WHERE '+' AND '.join(k+'=?' for k in pk),[row[k] for k in pk]).fetchone()
|
|
|
++ if table=='source_records':
|
|
|
++ # Asset remapping may resolve to a previously imported archive.
|
|
|
++ # Rebuilt importer generations must reuse its exact source locator.
|
|
|
++ located=c.execute('SELECT * FROM source_records WHERE asset_path=? AND line_number=?',
|
|
|
++ (row['asset_path'],row['line_number'])).fetchone()
|
|
|
++ if located:
|
|
|
++ voc_db.require(all(located[k]==value for k,value in row.items() if k!='id'),
|
|
|
++ 'SOURCE_LOCATOR_CONFLICT')
|
|
|
++ mapping[original['id']]=located['id']
|
|
|
++ delta['duplicate'][table]=delta['duplicate'].get(table,0)+1
|
|
|
++ continue
|
|
|
+ if table=='batches' and old and old['archive_sha256']==row['archive_sha256']:
|
|
|
+ mapping[original['id']]=old['id'];delta['duplicate'][table]=delta['duplicate'].get(table,0)+1;continue
|
|
|
+ # The same timestamped price observation may be re-exported under a new source locator.
|
|
|
+@@ -191,6 +202,17 @@
|
|
|
+ if old and table not in STABLE:
|
|
|
+ voc_db.require(len(pk)==1 and pk[0] in ('id','path','asset_path'),'CONFLICTING_RELATION:'+table)
|
|
|
+ col=pk[0]
|
|
|
++ if col=='id':
|
|
|
++ # Related evidence from older importer generations may already
|
|
|
++ # have a namespaced ID. Reuse it only when every fact and FK agrees.
|
|
|
++ facts=[k for k in columns if k!=col]
|
|
|
++ equivalent=c.execute('SELECT '+col+' FROM '+table+' WHERE '+
|
|
|
++ ' AND '.join(k+' IS ?' for k in facts)+' ORDER BY '+col+' LIMIT 1',
|
|
|
++ [row[k] for k in facts]).fetchone()
|
|
|
++ if equivalent:
|
|
|
++ mapping[original[col]]=equivalent[col]
|
|
|
++ delta['duplicate'][table]=delta['duplicate'].get(table,0)+1
|
|
|
++ continue
|
|
|
+ if table=='assets':row[col]='batches/'+im['archive_sha256'][:16]+'/'+row[col]
|
|
|
+ elif table=='collection_requests':raise ValueError('CONFLICTING_COLLECTION_REQUEST')
|
|
|
+ else:row[col]=hashlib.sha256((im['generation']+':'+str(original[col])).encode()).hexdigest()
|