Giter VIP home page Giter VIP logo

Comments (8)

lucaong avatar lucaong commented on June 2, 2024

Hi @jimbung ,
MiniSearch by default does not support searching in the middle of a word. It only supports searching at the beginning of the word, using prefix search, and/or for slightly misspelled words using fuzzy search.

That said, it is possible to implement search in the middle of the world, at the cost of a larger index, by following the instructions in this other discussion (and in particular in this comment).

from minisearch.

jimbung avatar jimbung commented on June 2, 2024

Hi @lucaong , thank u very much for quick response on the issue.
i tried as the following as the processTerm you mentioned above, but unfortunately some text cannot be searched out (before using processTerm function, they can be searched out).
below is the code, please have a look if i am wrong with somewhere.

const suffixes = (term, minLength) => {
  if (term == null) { return []; }
  const tokens = [];
  for (let i = 0; i <= term.length - minLength; i++) {
    tokens.push(term.slice(i));
  }
  return tokens;
}
const idfield = "order_id";
const miniSearch = new MiniSearch({
      idField: idfield,
      fields: ["suscep", "action.comment", "action.game.comment"],
      extractField: (document, fieldName) => {
          const arrFields = fieldName.split(".");
          if (arrFields.length === 2) {
            return (document[arrFields[0]] || [])
              .map((arrField: any) => arrField[arrFields[1]] || "")
              .join(" ");
          } else if (arrFields.length === 3) {
            const tmparr = (document[arrFields[0]] || []).flatMap(
              (arrField: any) => arrField[arrFields[1]] || []
            );
            return tmparr.map((s: any) => s[arrFields[2]] || "").join(" ");
          }

          // Access fields in simple path (such as a.b.c)
          return fieldName
            .split(".")
            .reduce((doc, key) => doc && doc[key], document);
      },
      processTerm: (term) => suffixes(term, 3),
      searchOptions: {
        processTerm: MiniSearch.getDefault('processTerm'),
        prefix: true,
      },
    });

Thanks!

from minisearch.

lucaong avatar lucaong commented on June 2, 2024

Hi @jimbung ,
I did a quick test, only including the processTerm logic and excluding the extractTerm part, and it seems to work correctly:

const suffixes = (term, minLength) => {
  if (term == null) { return []; }
  const tokens = [];
  for (let i = 0; i <= term.length - minLength; i++) {
    tokens.push(term.slice(i));
  }
  return tokens;
}
const miniSearch = new MiniSearch({
      fields: ["text"],
      processTerm: (term) => suffixes(term, 3),
      searchOptions: {
        processTerm: MiniSearch.getDefault('processTerm'),
        prefix: true,
      },
    });

const docs = [{id: 1, text: "something"}, {id: 2, text: 'something else'}]

miniSearch.addAll(docs)

miniSearch.search('thi')
/* >
[
  {
    id: 1,
    score: 0.10047016592300792,
    terms: [ 'thing' ],
    match: { thing: [Array] }
  },
  {
    id: 2,
    score: 0.084675550210326,
    terms: [ 'thing' ],
    match: { thing: [Array] }
  }
]
*/

Later today or tomorrow I will probably be able to test your code more in details. In the meanwhile, a few suggestions:

  • make sure you use the latest MiniSearch version if you do not already use it.
  • try to find if the problem is with the extractField part or the processTerm part
  • if possible, provide an example with data to reproduce the issue (ideally, a complete example where some result that you expect to be found is not found). This will help to spot the issue.

Good luck!

from minisearch.

jimbung avatar jimbung commented on June 2, 2024

Hi @lucaong ,
Thanks for quick reply.
I am using "minisearch": "^6.2.0" currently. is it the latest?
I'll check your suggestions later.
Thank you very much!

from minisearch.

lucaong avatar lucaong commented on June 2, 2024

Yes, its the latest 👍

from minisearch.

lucaong avatar lucaong commented on June 2, 2024

@jimbung did you manage to resolve your problem? If not, you can post more details here, ideally some code to reproduce the problem, and I will try to help you.

from minisearch.

jimbung avatar jimbung commented on June 2, 2024

hi @lucaong , thanks a lot for reminding me. Sorry i didnot post timely. The problem has been solved according to your suggestion. Thank u again for all the great helps :-)

from minisearch.

lucaong avatar lucaong commented on June 2, 2024

Thank you @jimbung , happy to know your issue is solved! I will then mark the issue as closed.

from minisearch.

Related Issues (20)

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.