Giter VIP home page Giter VIP logo

Comments (11)

ts-thomas avatar ts-thomas commented on May 5, 2024 1

Supporting both formats is possible. The doc configuration needs a way to keep JSON standard compatibility.

from flexsearch.

ts-thomas avatar ts-thomas commented on May 5, 2024

@mahnunchik Thanks for the report. Could you provide me the used configuration or a short example please?

from flexsearch.

mahnunchik avatar mahnunchik commented on May 5, 2024

Hi @ts-thomas

import FlexSearch from 'flexsearch';
import waypoints from './data/waypoints';

const index = new FlexSearch({
  doc: {
    id: "code",
    field: {
      code: {
        split: /\s+/,
        tokenize: "strict",
      },
      title: {
        split: /[\s()-]+/,
        tokenize: "forward",
      },
    },
  },
});

//console.time('index');
index.add(waypoints);
//console.timeEnd('index');

export default index;

Data: https://gist.github.com/mahnunchik/6920a1039a3da4ef22177521a800642d

from flexsearch.

ts-thomas avatar ts-thomas commented on May 5, 2024

@mahnunchik Sorry for the late answer. The issue here was the split-field needs a string value (to keep json compatibility):

const index = new FlexSearch({
  doc: {
    id: "code",
    field: {
      code: {
        split: "/\s+/",
        tokenize: "strict",
      },
      title: {
        split: "/[\s()-]+/",
        tokenize: "forward",
      },
    },
  },
});

from flexsearch.

mahnunchik avatar mahnunchik commented on May 5, 2024

@ts-thomas it would be more predictable to have usual regexp in normal js configuration, not a string of js regexp. Or support both formats.

from flexsearch.

mahnunchik avatar mahnunchik commented on May 5, 2024

Hi @ts-thomas

It seems "/\s+/" from your comment not works as expected in 0.6.22.

from flexsearch.

wamir79 avatar wamir79 commented on May 5, 2024

Hi @ts-thomas
it doesn't work for me as well. the content.split(this.split) not works as this.split is just a string and not regex.
if i use regex in the field definition the clone_object is not working correctly:
clone_object({a:/a/}) = {a:{}}

from flexsearch.

wamir79 avatar wamir79 commented on May 5, 2024

patch to clone_object:

		function clone_object(obj) {
			const clone = create_object();

			for (const key in obj) {
				if (obj.hasOwnProperty(key)) {
					const value = obj[key];

					if (is_array(value)) {
						clone[key] = value.slice(0);
					} else if (value instanceof RegExp) {
						clone[key] = value;
					} else if (is_object(value)) {
						clone[key] = clone_object(value);
					} else {
						clone[key] = value;
					}
				}
			}

			return clone;
		}

from flexsearch.

ts-thomas avatar ts-thomas commented on May 5, 2024

@wamir79 thanks for providing a fix.

from flexsearch.

mahnunchik avatar mahnunchik commented on May 5, 2024

Should this issue be closed?

from flexsearch.

ts-thomas avatar ts-thomas commented on May 5, 2024

Please change over to the version >= 0.7.x which solves that issue, thanks a lot.

from flexsearch.

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.