Commit cf9c6011 by Sxy

fix: 优化一版

parent 5a2f954a
......@@ -10,6 +10,7 @@ cerebro: http://192.168.18.102:3000
cnlength:"中文长度",
enlength:"英文长度",
otherlength:"数字特殊符号长度",
pinyin:"同音字设计",
"name" : {
"type" : "keyword",
"fields" : {
......@@ -181,6 +182,9 @@ cerebro: http://192.168.18.102:3000
},
"otherlength": {
"type": "integer"
},
"pinyin":{
"type": "keyword"
}
}
}
......
const router = require('koa-router')()
const start = require("../start")
const start = require("../startV1")
const es = require("../client/esclient");
router.get('/', async (ctx, next) => {
await ctx.render('index')
......@@ -8,29 +8,37 @@ router.get('/', async (ctx, next) => {
router.post('/list', async (ctx, next) => {
const { page, limit, conditions, name } = ctx.request.body;
let query = await start(name, conditions)
query = {
query: {
bool: {
should: query
}
},
"from": (page - 1) * limit,
"size": limit,
}
console.log(JSON.stringify(query))
const data = await es.search({
index: "trademarkv2",
body: query
})
const { body: { hits: { total, hits } } } = data;
ctx.body = {
list: hits.map(item => {
return {
name: item._source.name
}
}),
count: total.value,
query
if (query.length > 0) {
query = {
query: {
bool: {
should: query
}
},
"from": (page - 1) * limit,
"size": limit,
}
console.log(JSON.stringify(query))
const data = await es.search({
index: "trademarkv3",
body: query
})
const { body: { hits: { total, hits } } } = data;
ctx.body = {
list: hits.map(item => {
return {
name: item._source.name
}
}),
count: total.value,
query
}
} else {
ctx.body = {
list: [],
count: 0,
query
}
}
})
......
const { pinyin } = require('pinyin-pro');
const es = require("./client/esclient");
// 加字词
const addString = "新,真,旧,早,红,亮,香,稳,热,喜,闹,急,多,少,高,矮,胖,瘦,漂亮,金黄,冷艳,动人,大,初级,高级,简单,复杂,细,长,短,很,非常,极,十分,最,顶,太,更,挺,极其,格外,分外,更加,越,越发,有点儿,稍,稍微,略微,几乎,过于,尤其,都,全,总,总共,共,统统,仅仅,只,光,净,一概,一律,一齐,单,已经,曾经,早已,刚刚,正,正在,就,就要,将,将要,曾,刚,才,在,马上,立刻,,渐渐,早晚,从来,终于,一向,向来,从来,总是,始终,往往,永,赶紧,仍然,还是,屡次,依然,重新,还,再,再三,偶尔,顿时,终于,常,常常,时常,时时,到处,处处,随处,四处,不,没,没有,不用(甭),必,必须,必定,准,的确,未,别,莫,勿,是否,不必,不曾,忽然,猛然,公然,特意,亲自,大肆,肆意,悄悄,连忙,赶紧,暗暗,难道,决,岂,反正,也许,大约,大概,果然,居然,竟然,究竟,幸而,幸亏,偏偏,明明,恰恰,未免,只好,不妨,索性,简直,就,可,难怪,反倒,何尝,何必,院,所,厂,部,行,局,司,署,厅,处,办,宫,园,馆,场,室,间,轩,屋,堂,斋,寨,庙,寺,观,村,镇,乡,府,庄,屯,港,岛,城,口,市,区,州,县,省,屿,站,岭,店,街,巷,里,都,楼,亭,堡,铺,湾,渡,社,营,洞,湖,集,坡,塔,阁,居,宫,源,校,斤,尺,亩,度,寸,米,尺,千克,克拉,吨,把,部,场,滴,顶,束,朵,副,个,根,间,件,棵,颗,口,块,粒,辆,片,扇,双,所,座,套,条,头,张,只,台,面,本,匹,尾,框,条,例,瓶,盒,杯,箱,桶,罐,群,束,方,园,正,酸,甜,苦,辣,咸,香,臭,麻,涩,鲜,红,橙,黄,绿,青,蓝,紫,黑,白,灰,棕,褐,金,银"
const xuci = "而,何,乎,乃,其,且,若 ,所,为,焉,也,以,因,于,与,则,者,之,卡,斯,特,尔,儿"
// 1. 完全相同
async function one(name, length, zhlength, enlength, otherlength, boost) {
return {
"must": [
{
"term": {
"length": {
"value": length
}
}
},
{
bool: {
should: [
{
"term": {
"name": {
value: name,
"boost": boost
},
}
},
{
"match": {
"name.jingque": {
query: name,
"boost": boost
},
}
}
]
}
}
]
}
}
// 2. 完全相同加英文/图形符号,后缀
async function two(name, length, zhlength, enlength, otherlength, boost) {
return {
must: [
{
range: {
length: {
gt: length
}
}
}, {
term: {
cnlength: zhlength
}
},
{
"match_phrase": {
"name.standard": {
query: name,
"boost": boost
}
}
},
{
"wildcard": {
"name.jingque": {
"value": `${name.toLowerCase()}*`,
"boost": boost
}
}
},
{
bool: {
should: [
{
range: {
enlength: {
gt: enlength
}
}
}, {
range: {
otherlength: {
gt: otherlength
}
}
}
]
}
}
]
}
}
// 3. 完全相同加英文/图形符号,前缀,
async function three(name, length, zhlength, enlength, otherlength, boost) {
return {
must: [
{
range: {
length: {
gt: length
}
}
}, {
term: {
cnlength: zhlength
}
},
{
"match_phrase": {
"name.standard": {
query: name,
"boost": boost
}
}
},
{
"wildcard": {
"name.jingque": {
"value": `*${name.toLowerCase()}`,
"boost": boost
}
}
},
{
bool: {
should: [
{
range: {
enlength: {
gt: enlength
}
}
}, {
range: {
otherlength: {
gt: otherlength
}
}
}
]
}
}
]
}
}
// 4. 倒序
async function four(name, length, zhlength, enlength, otherlength, boost) {
return await one(name.split('').reverse().join(''), length, zhlength, enlength, otherlength, boost)
}
// 5. 倒序加英文/图形符号,后缀
async function five(name, length, zhlength, enlength, otherlength, boost) {
return await two(name.split('').reverse().join(''), length, zhlength, enlength, otherlength, boost)
}
// 6. 倒序加英文/图形符号,前缀
async function six(name, length, zhlength, enlength, otherlength, boost) {
return await three(name.split('').reverse().join(''), length, zhlength, enlength, otherlength, boost)
}
// 7. 同音不同字
async function seven(name, length, zhlength, enlength, otherlength, boost) {
return {
should: [
{
bool: {
"must": [
{
term: {
length: {
value: length
}
}
},
{
term: {
pinyin: {
value: pinyin(name, { toneType: 'none' })
}
}
},
{
"match_phrase": {
"name.all_pinyin": {
query: name,
"boost": boost
},
}
}
],
"must_not": [
{
"term": {
"name.jingque": {
"value": name.toLowerCase()
}
}
}
]
}
}
]
}
}
// 8. 同音不同字加英文/图形符号,后缀
async function eight(name, length, zhlength, enlength, otherlength, boost) {
return {
should: [
{
bool: {
"must": [
{
range: {
length: {
gt: length
}
}
},
{
term: {
cnlength: zhlength
}
},
{
"match_phrase": {
"name.all_pinyin": {
query: name,
"boost": boost
},
}
},
{
"wildcard": {
"pinyin": {
"value": `${pinyin(name, { toneType: 'none' })}*`,
"boost": boost
}
}
},
{
bool: {
should: [
{
range: {
enlength: {
gt: enlength
}
}
}, {
range: {
otherlength: {
gt: otherlength
}
}
}
]
}
}
],
"must_not": [
{
match_phrase: {
"name.standard": {
query: name
}
}
}
]
}
}
]
}
}
// 9. 同音不同字加英文/图形符号,前缀
async function nine(name, length, zhlength, enlength, otherlength, boost) {
return {
should: [
{
bool: {
"must": [
{
range: {
length: {
gt: length
}
}
},
{
term: {
cnlength: zhlength
}
},
{
"match_phrase": {
"name.all_pinyin": {
query: name,
"boost": boost
},
}
},
{
"wildcard": {
"pinyin": {
"value": `*${pinyin(name, { toneType: 'none' })}`,
"boost": boost
}
}
},
{
bool: {
should: [
{
range: {
enlength: {
gt: enlength
}
}
}, {
range: {
otherlength: {
gt: otherlength
}
}
}
]
}
}
],
"must_not": [
{
match_phrase: {
"name.standard": {
query: name
}
}
}
]
}
}
]
}
}
// 10. 同音不同字倒序
async function ten(name, length, zhlength, enlength, otherlength, boost) {
return await seven(name.split('').reverse().join(''), length, zhlength, enlength, otherlength, boost)
}
// 11.同音不同字倒序加英文/图形符号,后缀
async function eleven(name, length, zhlength, enlength, otherlength, boost) {
return await eight(name.split('').reverse().join(''), length, zhlength, enlength, otherlength, boost)
}
// 12.同音不同字倒序加英文/图形符号,前缀
async function twelve(name, length, zhlength, enlength, otherlength, boost) {
return await nine(name.split('').reverse().join(''), length, zhlength, enlength, otherlength, boost)
}
// 13.完全相同后缀加字/词近似,如:小米与小米智慧或小米米等;
async function thirteen(name, length, zhlength, enlength, otherlength, boost) {
return {
should: [
{
bool: {
"must": [
{
"match": {
"name.standard": {
"query": name,
"operator": "and",
"boost": boost
}
}
},
{
"match": {
"name.tongyici": {
"query": addString,
"analyzer": "mypattern",
"boost": boost
}
}
},
{
"wildcard": {
"name.jingque": {
"value": `${name.toLowerCase()}*`,
"boost": boost
}
}
}
],
"must_not": [
{
"term": {
"name.jingque": {
"value": name.toLowerCase()
}
}
}
]
}
},
{
bool: {
"must": [
{
"match": {
"name.standard": {
"query": name,
"operator": "and",
"boost": boost
}
}
},
{
"wildcard": {
"name.jingque": {
"value": `${name.toLowerCase()}*`,
"boost": boost
}
}
}
],
"must_not": [
{
"term": {
"name.jingque": {
"value": name.toLowerCase()
}
}
}
]
}
}
]
}
}
// 14.完全相同前缀加字/词近似,如:小米与智慧小米或米小米等;
async function fourteen(name, length, zhlength, enlength, otherlength, boost) {
return {
should: [
{
bool: {
"must": [
{
"match": {
"name.standard": {
"query": name,
"operator": "and",
"boost": boost
}
}
},
{
"match": {
"name.tongyici": {
"query": addString,
"analyzer": "mypattern",
"boost": boost
}
}
},
{
"wildcard": {
"name.jingque": {
"value": `*${name.toLowerCase()}`,
"boost": boost
}
}
}
],
"must_not": [
{
"term": {
"name.jingque": {
"value": name.toLowerCase()
}
}
}
]
}
},
{
bool: {
"must": [
{
"match": {
"name.standard": {
"query": name,
"operator": "and",
"boost": boost
}
}
},
{
"wildcard": {
"name.jingque": {
"value": `*${name.toLowerCase()}`,
"boost": boost
}
}
}
],
"must_not": [
{
"term": {
"name.jingque": {
"value": name.toLowerCase()
}
}
}
]
}
}
]
}
}
// 15.倒序后缀加字/词近似,如:华为与为华智慧或为华大等;
async function fifteen(name, length, zhlength, enlength, otherlength, boost) {
return await thirteen(name.split('').reverse().join(''), length, zhlength, enlength, otherlength, boost);
}
// 16.倒序前缀加字/词近似,如:华为与智慧为华或大为华等;
async function sixteen(name, length, zhlength, enlength, otherlength, boost) {
return await fourteen(name.split('').reverse().join(''), length, zhlength, enlength, otherlength, boost);
}
// 17.相同词中加虚词或相同词
async function seventeen(name, length, zhlength, enlength, otherlength, boost) {
return {
should: [
{
bool: {
must: [
{
"match": {
"name.standard": {
"query": name,
"operator": "and",
"boost": boost
}
}
},
{
match: {
"name.standard": {
"query": xuci,
"boost": boost
}
}
},
{
term: {
cnlength: zhlength + 1
}
},
]
}
}
]
}
}
// 18.相同词中加虚词加英文/图形符号
async function eighteen(name, length, zhlength, enlength, otherlength, boost) {
return {
should: [
{
bool: {
must: [
{
"match": {
"name.standard": {
"query": name,
"operator": "and",
"boost": boost
}
}
},
{
match: {
"name.standard": {
"query": xuci,
"boost": boost
}
}
},
{
term: {
cnlength: zhlength + 1
}
},
{
range: {
length: {
gt: length + 1
}
}
}, {
bool: {
should: [
{
range: {
enlength: {
gt: enlength
}
}
}, {
range: {
otherlength: {
gt: otherlength
}
}
}
]
}
}
]
}
}
]
}
}
// 19.商标文字含义相同/近似(也包含拼音/英文)
async function nineteen(name, length, zhlength, enlength, otherlength, boost) {
return {
should: [
{
"bool": {
"must": [
{
"match_phrase": {
"name.tongyici": {
"query": name,
"boost": boost
}
}
}
],
"must_not": [
{
"term": {
"name.jingque": {
"value": name.toLowerCase()
}
}
}, {
"wildcard": {
"name.jingque": {
"value": `*${name.toLowerCase()}*`
}
}
}
]
}
},
{
"bool": {
"must": [
{
"match_phrase": {
"name.english": {
"query": name,
"boost": boost
}
}
}
],
"must_not": [
{
"term": {
"name.jingque": {
"value": name.toLowerCase()
}
}
}, {
"wildcard": {
"name.jingque": {
"value": `*${name.toLowerCase()}*`
}
}
}
]
}
}
]
}
}
// 20.同字形不同音或同字形不同音
async function twenty(name, length, zhlength, enlength, otherlength, boost) {
return {
should: [
{
"bool": {
"must": [
{
"term": {
"length": {
"value": length
}
}
},
{
"match_phrase": {
"name.standard": {
"analyzer": "xingjinzi",
"query": name,
"boost": boost
}
}
}
],
"must_not": [
{
"term": {
"name.jingque": {
"value": name.toLowerCase()
}
}
}
]
}
}
]
}
}
// 21.同字形不同音加英文/图形符号
async function twentyOne(name, length, zhlength, enlength, otherlength, boost) {
return {
should: [
{
"bool": {
"must": [
{
range: {
length: {
gt: length
}
}
}, {
term: {
cnlength: zhlength
}
},
{
"match_phrase": {
"name.standard": {
"analyzer": "xingjinzi",
"query": name,
"boost": boost
}
}
}, {
bool: {
should: [
{
range: {
enlength: {
gt: enlength
}
}
}, {
range: {
otherlength: {
gt: otherlength
}
}
}
]
}
}
],
"must_not": [
{
match_phrase: {
"name.standard": {
query: name
}
}
}
]
}
}
]
}
}
// 22.相同减字/词或相同减字/词
async function twentyTwo(name, length, zhlength, enlength, otherlength, boost) {
let array = [];
for (let i = 0; i < length - 1; i++) {
let query = {
bool: {
"must": [
{
match: {
"name.standard": {
query: name
}
}
}, {
term: {
length: length - i - 1
}
},
{
"fuzzy": {
"name.jingque": {
"value": name.toLowerCase(),
"fuzziness": i + 1,
"max_expansions": 10000,
"boost": boost / 2
}
}
}
]
}
}
array.push(query);
}
return {
should: [
...array
]
}
}
// 23.相同减字/词或相同减字/词加英文/图形符号,后缀
async function twentyThree(name, length, zhlength, enlength, otherlength, boost) {
const query = await twentyTwo(name, length, zhlength, enlength, otherlength, boost);
const data = await es.search({
index: "trademarkv3",
body: {
query: {
bool: query
}
}
})
const { body: { hits: { total, hits } } } = data;
const names = hits.map(item => {
return item._source.name
})
let array = []
for (let val of names) {
val = val.trim();
const length = val.length;
const zhlength = val.trim().replace(/[^\u4E00-\u9FA5]/g, '').length;
const enlength = val.trim().replace(/[^a-zA-Z]/g, '').length;
const otherlength = length - zhlength - enlength;
array.push({
bool: await two(val, length, zhlength, enlength, otherlength, boost)
})
}
if (array.length > 0) {
return {
should: array
}
} else {
return null
}
}
// 24.相同减字/词或相同减字/词加英文/图形符号,前缀
async function twentyFour(name, length, zhlength, enlength, otherlength, boost) {
const query = await twentyTwo(name, length, zhlength, enlength, otherlength, boost);
const data = await es.search({
index: "trademarkv3",
body: {
query: {
bool: query
}
}
})
const { body: { hits: { total, hits } } } = data;
const names = hits.map(item => {
return item._source.name
})
let array = []
for (let val of names) {
val = val.trim();
const length = val.length;
const zhlength = val.trim().replace(/[^\u4E00-\u9FA5]/g, '').length;
const enlength = val.trim().replace(/[^a-zA-Z]/g, '').length;
const otherlength = length - zhlength - enlength;
array.push({
bool: await three(val, length, zhlength, enlength, otherlength, boost)
})
}
if (array.length > 0) {
return {
should: array
}
} else {
return null
}
}
const funs = ["",
one, two, three, four,
five, six, seven, eight,
nine, ten, eleven, twelve,
thirteen, fourteen, fifteen, sixteen,
seventeen, eighteen, nineteen, twenty,
twentyOne, twentyTwo, twentyThree, twentyFour
]
/**
*
* @param {*} name 商标名
* @param {*} conditions 查询条件
*/
async function start(name, conditions) {
name = name.trim();
const length = name.length;
const zhlength = name.trim().replace(/[^\u4E00-\u9FA5]/g, '').length;
const enlength = name.trim().replace(/[^a-zA-Z]/g, '').length;
const otherlength = length - zhlength - enlength;
let searchArry = [];
let len = funs.length
for (let val of conditions) {
const query = await funs[val](name, length, zhlength, enlength, otherlength, Math.pow(10, len - val + 1));
if (query) {
searchArry.push({
bool: query
})
}
}
return searchArry;
}
module.exports = start
\ No newline at end of file
......@@ -132,6 +132,9 @@
},
"otherlength": {
"type": "integer"
},
"pinyin": {
"type": "keyword"
}
}
}
......
......@@ -67,18 +67,29 @@
<script>
const options = [
"1. 完全相同",
"2. 完全相同加英文/图形符号,如:小米与小米A或A小米",
"3. 倒序或倒序加英文/图形符号,如:小米与米小,全聚德与德聚全;小米与米小A或A米小;",
"4.同音不同字或同音不同字加英文/图形符号,如:华为与铧为,华为与铧为A或A铧为;(同词加字母的组合展示)",
"5. 同音不同字倒序或同音不同字倒序加英文/图形符号,如:华为与为铧或与为铧A或A为铧",
"6. 完全相同后缀加字/词近似,如:小米与小米智慧或小米米等;",
"7. 完全相同前缀加字/词近似,如:小米与智慧小米或米小米等;",
"8. 倒序后缀加字/词近似,如:华为与为华智慧或为华大等;",
"9. 倒序前缀加字/词近似,如:华为与智慧为华或大为华等;",
"10. 相同词中加虚词或相同词中加虚词加英文/图形符号,如:小米与小之米或小之米A;",
"11. 商标文字含义相同/近似(也包含拼音/英文)",
"12. 同字形不同音或同字形不同音加英文/图形符号,如:华为与毕为或毕为A;",
"13. 相同减字/词或相同减字/词加英文/图形符号,如:全聚德与全德或全德A;"
"2. 完全相同加英文/图形符号,后缀",
"3. 完全相同加英文/图形符号,前缀",
"4. 倒序",
"5. 倒序加英文/图形符号,后缀",
"6. 倒序加英文/图形符号,前缀",
"7. 同音不同字",
"8. 同音不同字加英文/图形符号,后缀",
"9. 同音不同字加英文/图形符号,前缀",
"10.同音不同字倒序",
"11.同音不同字倒序加英文/图形符号,后缀",
"12.同音不同字倒序加英文/图形符号,前缀",
"13.完全相同后缀加字/词近似,如:小米与小米智慧或小米米等;",
"14.完全相同前缀加字/词近似,如:小米与智慧小米或米小米等;",
"15.倒序后缀加字/词近似,如:华为与为华智慧或为华大等;",
"16.倒序前缀加字/词近似,如:华为与智慧为华或大为华等;",
"17.相同词中加虚词",
"18.相同词中加虚词加英文/图形符号",
"19.商标文字含义相同/近似(也包含拼音/英文)",
"20.同字形不同音",
"21.同字形不同音加英文/图形符号",
"22.相同减字/词",
"23.相同减字/词加英文/图形符号,后缀",
"24.相同减字/词加英文/图形符号,前缀"
];
new Vue({
el: '#app',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment