Code Monkey home page Code Monkey logo

Comments (7)

I-Want-ToBelieve avatar I-Want-ToBelieve commented on June 14, 2024

I found that English supports fuzzy matching but Chinese does not
It only lists the ones starting with "节", but not the ones containing "节"
image
image

from wfm-localization.

I-Want-ToBelieve avatar I-Want-ToBelieve commented on June 14, 2024

@KycKyc I can help to improve this, including code writing and testing

from wfm-localization.

KycKyc avatar KycKyc commented on June 14, 2024

@I-Want-ToBelieve Hello !
I am working on WS rework right now, do not have time to properly setup repository to be able to work with it right out of the box.

But i put sources together here: https://github.com/42bytes-team/wfm-seeker

It's v2 version of our fuzzy search component, should be deployed along with new websockets and part of a new API

from wfm-localization.

I-Want-ToBelieve avatar I-Want-ToBelieve commented on June 14, 2024

@KycKyc Hi!

Is the fuzzy search component currently deployed online the version of this repo https://github.com/42bytes-team/wfm-seeker ?
I found that the online warframe market can search and match items that do not start with user input, but this github repo can only match items whose strings start with the input

The online:
image

The repo :

wfm-seeker on  master [?] via  v18.16.0 
❯ node test.mjs link
(node:53744) ExperimentalWarning: Import assertions are not a stable feature of the JavaScript language. Avoid relying on their current behavior and syntax as those might change in a future version of Node.js.
(Use `node --trace-warnings ...` to show where the warning was created)
availableToSelect:  [ 'Link Armor', 'Link Health', 'Link Shields' ]
[ '<b key={cnt}>Link</b>', "<span key={'fin'}> Armor</span>" ]
[ '<b key={cnt}>Link</b>', "<span key={'fin'}> Health</span>" ]
[ '<b key={cnt}>Link</b>', "<span key={'fin'}> Shields</span>" ]
(node:53744) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time

This test.mjs is the core logic of the fuzzy search component I extracted for testing

import data from './data.json' assert { type: 'json' }

const inputValue = process.argv.at(2) ?? 'link'


const nameKey = 'item_name'
const _nameKey = (nameKey || 'name')
const items = data.payload.items

const inputEscapingMap = [
  [/\\/g, '\\\\'],
  [/\(/g, '\\('],
  [/\)/g, '\\)'],
  [/\[/g, '\\['],
  [/\]/g, '\\]'],
]


const value = inputEscapingMap.reduce((acc, pair) => {
  return acc.replace(pair[0], pair[1]);
}, inputValue)

const parts = value.trim().split(' ')

const regexBase = parts.reduce((regexBase, part, index) => (part.length > 0 ? (regexBase += `(^|.*?\\s·)(${part})`) : regexBase), '');

const regex = new RegExp(regexBase, 'ig')

const itemMatchPairs = items
  .map((item) => {
    if (regex === null) {
      return [1, item];
    }

    let name = item[_nameKey]
    let matchedlenght = name.match(regex)?.[0].length || 0;
    return [matchedlenght, item];
  })
    .filter((pair) => {
      return pair[0] > 0;
    }).sort((a, b) => {
      let matchLenghtA = a[0];
      let matchLenghtB = b[0];
      let itemA = a[1];
      let itemB = b[1];
      let aName = itemA[_nameKey]
      let bName = itemB[_nameKey]
      let aGroup = itemA.group || 'without'
      let bGroup = itemB.group || 'without'

      if (aGroup === bGroup) {
        if (matchLenghtA === matchLenghtB) {
          return aName.localeCompare(bName);
        }

        return matchLenghtA - matchLenghtB;
      }

      let aPriority = groupPriority[aGroup] || groupPriority.with;
      let bPriority = groupPriority[bGroup] || groupPriority.with;
      if (aPriority === bPriority) {
        return aGroup.localeCompare(bGroup);
      }

      return aPriority - bPriority;
    })

const availableToSelect = itemMatchPairs.map((pair) => pair[1])

console.log('availableToSelect: ', availableToSelect.slice(0, 6).map((it) => it[_nameKey]))

for (const [index, item] of availableToSelect.entries()) {
  let name = item[_nameKey]
  const textNodes = []

  for (let charIndex = name.search(regex), cnt = 0; charIndex !== -1 && cnt < 30; cnt++) {
      let matchedlenght = name.match(regex)[0].trim().length;

      if (charIndex !== 0) {
          charIndex++;
          textNodes.push(`<span key={cnt}>${name.slice(0, charIndex)}</span>`);
      }

      textNodes.push(`<b key={cnt}>${name.slice(charIndex, charIndex + matchedlenght)}</b>`);
      name = name.slice(charIndex + matchedlenght);
      charIndex = name.search(regex);
  }

  if (name.length > 0) {
      textNodes.push(`<span key={'fin'}>${name}</span>`);
  }

  console.log(textNodes)
}

The data.json is https://api.warframe.market/v1/items response

from wfm-localization.

lonnstyle avatar lonnstyle commented on June 14, 2024

@I-Want-ToBelieve Hi! The WFM-Seeker repo will be deployed in the next frontend update as we made a tiny change for · character matching in Simplified Chinese
and we've already noticed an issue on the regex pattern (^|.*?\\s·) which should be changed as (^|.*?[\\s·])
anything other than that should be same as the current version on site

edit: just did a quick test on it, should be the problem of missing [] causing it unable to match from middle

from wfm-localization.

I-Want-ToBelieve avatar I-Want-ToBelieve commented on June 14, 2024

@lonnstyle hello
Just change (^|.*?[\\s·]) to(^|.*?[\\s·]?) that way it looks fine.

image

wfm-seeker on  master [?] via  v18.16.0 
❯ node test.mjs link
(node:14810) ExperimentalWarning: Import assertions are not a stable feature of the JavaScript language. Avoid relying on their current behavior and syntax as those might change in a future version of Node.js.
(Use `node --trace-warnings ...` to show where the warning was created)
(node:14810) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
availableToSelect:  [
  'Link Armor',
  'Link Health',
  'Link Shields',
  'Abating Link',
  'Catalyzer Link',
  'Aklex Prime Link'
]
[ '<b key={cnt}>Link</b>', "<span key={'fin'}> Armor</span>" ]
[ '<b key={cnt}>Link</b>', "<span key={'fin'}> Health</span>" ]
[ '<b key={cnt}>Link</b>', "<span key={'fin'}> Shields</span>" ]
[ '<b key={cnt}>Abating Link</b>' ]
[ '<b key={cnt}>Catalyzer Link</b>' ]
[ '<b key={cnt}>Aklex Prime Link</b>' ]
[ '<b key={cnt}>Afuris Prime Link</b>' ]
[ '<b key={cnt}>Akbolto Prime Link</b>' ]
[ '<b key={cnt}>Akvasto Prime Link</b>' ]
[ '<b key={cnt}>Akbronco Prime Link</b>' ]
[ '<b key={cnt}>Akjagara Prime Link</b>' ]
[ '<b key={cnt}>Aksomati Prime Link</b>' ]
[ '<b key={cnt}>Akstiletto Prime Link</b>' ]
[ '<b key={cnt}>Twin Vipers Wraith Link</b>' ]

wfm-seeker on  master [?] via  v18.16.0 
❯ node test.mjs 节 cn
(node:14879) ExperimentalWarning: Import assertions are not a stable feature of the JavaScript language. Avoid relying on their current behavior and syntax as those might change in a future version of Node.js.
(Use `node --trace-warnings ...` to show where the warning was created)
(node:14879) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
灵快节拍 [ '灵快节' ]
正直·节奏 [ '正直·节' ]
赋能·节奏 [ '赋能·节' ]
皇家节奏 [ '皇家节' ]
节流降耗 [ '' ]
调节跳跃 [ '调节' ]
集气城市调节器场景 [ '集气城市调节' ]
使节 枪管 [ '使节' ]
使节 一套 [ '使节' ]
使节 枪机 [ '使节' ]
使节 枪托 [ '使节' ]
使节 蓝图 [ '使节' ]
availableToSelect:  [ '节流降耗', '使节 一套', '使节 枪托', '使节 枪机', '使节 枪管', '使节 蓝图' ]
[ '<b key={cnt}>节</b>', "<span key={'fin'}>流降耗</span>" ]
[ '<b key={cnt}>使节</b>', "<span key={'fin'}> 一套</span>" ]
[ '<b key={cnt}>使节</b>', "<span key={'fin'}> 枪托</span>" ]
[ '<b key={cnt}>使节</b>', "<span key={'fin'}> 枪机</span>" ]
[ '<b key={cnt}>使节</b>', "<span key={'fin'}> 枪管</span>" ]
[ '<b key={cnt}>使节</b>', "<span key={'fin'}> 蓝图</span>" ]
[ '<b key={cnt}>调节</b>', "<span key={'fin'}>跳跃</span>" ]
[ '<b key={cnt}>灵快节</b>', "<span key={'fin'}>拍</span>" ]
[ '<b key={cnt}>皇家节</b>', "<span key={'fin'}>奏</span>" ]
[ '<b key={cnt}>正直·节</b>', "<span key={'fin'}>奏</span>" ]
[ '<b key={cnt}>赋能·节</b>', "<span key={'fin'}>奏</span>" ]
[ '<b key={cnt}>集气城市调节</b>', "<span key={'fin'}>器场景</span>" ]

the test.mjs is 42bytes-team/wfm-seeker@72446de#diff-2b297e381f80175634ab045ed453022ac6eeb7fd7ce41357e9d5ec33222490de

from wfm-localization.

lonnstyle avatar lonnstyle commented on June 14, 2024

I'm closing this issue as it is more related to the seeker repo
we'll create a separated regex for Chinese searching, for any more feedback/suggestions, please open an issue at seeker repo or contact us via Discord

from wfm-localization.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.