Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

253
Vistas
In the Flexsearch Library, How to search all matching text?

I have a large text with 10 "hell" words in the document, and I want flexSearch to retrieve all the matches in the full text for me. I currently use the index. search method, but it can only retrieve the first hell, not include the rest. I don't know what's going on.

my core code:

import Flexsearch from "flexsearch";
//英文搜索
const searchENOptions = {
   encode: "icase",
   tokenize: "reverse",
   resolution: 9,
   doc: {
     id: "key",
     field: ["content"],
   },
};
this.indexEN = new Flexsearch(searchENOptions);
const { pages } = this.$site;
this.indexEN.add(pages);

const query = this.query.trim().toLowerCase(); // query keywords
let result = null;
if (!query) {
   return;
}

const regex = /[\x00-\x7F]/g;

// currently, the result only has one item.
result = this.indexEN.search(query).map((page) => {
    return {
        ...page,
        text: this.getSuggestionText(page),
      };
    });
}

function getSuggestionText(page) {
      const content = page.content; // fullText
      const queryIndex = content
        .toLowerCase()
        .indexOf(this.query.toLowerCase());
      const queryFirstWord = this.query.split(" ")[0];
      let startIndex =
        queryIndex === -1
          ? content.toLowerCase().indexOf(queryFirstWord.toLowerCase())
          : queryIndex;
      let prefix = "";
      if (startIndex > 15) {
        startIndex -= 15;
        prefix = "... ";
      }
      const text = page.content.substr(startIndex, SEARCH_RESULT_LENGTH);
      return highlightText(text, this.query) + prefix;
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda