perf(bridge): 商品检索改用短关键词并恢复分阶段计时
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { translateProductQuery } = require('../src/product-query');
|
||||
const { translateProductQuery, extractProductKeyword } = require('../src/product-query');
|
||||
|
||||
test('translateProductQuery: Chinese category alias -> English title', () => {
|
||||
const entries = [
|
||||
@@ -20,3 +20,20 @@ test('translateProductQuery: English query unchanged', () => {
|
||||
assert.equal(out.translated, false);
|
||||
assert.equal(out.query, 'hoop earrings');
|
||||
});
|
||||
|
||||
test('extractProductKeyword: drops quantities/currency/transaction words', () => {
|
||||
assert.equal(extractProductKeyword('We need 500 stainless steel rings wholesale under 10 dollars'), 'stainless steel rings');
|
||||
assert.equal(extractProductKeyword('500 rings'), 'rings');
|
||||
assert.equal(extractProductKeyword('do you have gold hoop earrings?'), 'gold hoop earrings');
|
||||
assert.equal(extractProductKeyword('do you accept returns on stainless steel rings'), 'stainless steel rings');
|
||||
});
|
||||
|
||||
test('extractProductKeyword: caps at 4 tokens, keeps CJK', () => {
|
||||
assert.equal(extractProductKeyword('neo stainless steel rings 500 pcs'), 'neo stainless steel rings');
|
||||
assert.equal(extractProductKeyword('简约不锈钢戒指'), '简约不锈钢戒指');
|
||||
});
|
||||
|
||||
test('extractProductKeyword: pure quantity/transaction returns empty', () => {
|
||||
assert.equal(extractProductKeyword('500 pcs wholesale'), '');
|
||||
assert.equal(extractProductKeyword(''), '');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user