krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
17.76k stars 753 forks source link

Not matching obvious matches? #750

Closed greggman closed 2 months ago

greggman commented 7 months ago

Is there an existing issue for this?

Description of the bug

v7.0.0

Given a list of strings, I search for 2 words, fuse results scores where entries with those 2 words are not scored high

The Fuse.js version where this bug is happening.

Other: 7.0.0

Is this a regression?

Which version did this behavior use to work in?

no idea. this is the first time I've used fuse

Steps To Reproduce

Load a bunch of simple records in with name, id Search for 2 words in name in some records

https://jsfiddle.net/greggman/3780hd6w/

Expected behavior

The entries with the 2 words have the highest score

For example if the entries were

1 "apple banana grape"
2 "apple pineapple banana"
3 "orange lemon banana"
4 "apple lime tangerine"
5 "strawberry kumquat lime"

And the search was

"apple banana"

Then I'd expect entries 1 and 2 to be the highest scored as they contain both words vs 3 and 4 which contain only 1 word each and 5 which contains none of the words I searched for

But that's not what I see

Screenshots

Example output:

Here's are the 5 entries that have both "color" and "webgpu" in them

596: Copy of Raw WebGPU article (no color)
957: WebGPU Points with size and texture and color
963: WebGPU Sprite Multiple - one vertex buffer, update verts, + color
975: WebGPU Points with size and texture and color, rotation, and (mips)
1020: WebGPU Vertex Buffer vertices - instanced colors with edge texture

And here's the results from searching with their score. The 5 entries are marked with =>. I'd have expected them to be the top 5 results.

   0.8648814814587134  967: Canvas with size 0 in WebGL, WebGPU, and Canvas2D
   0.8457978624729302  845: Canvas2D colorSpace srgb vs display-p3 conversion
   0.837951458636145   401: Lose and Restore WebGL Context
   0.8323656017334663  839: Canvas2D colorSpace srgb vs display-p3
   0.8267329803896175  108: DOS Too Much WebGL work
   0.8267329803896175   40: DOS Too Much WebGL work
   0.8253054085126572  944: WebGPU Simple Inter-Stage Variables by fn param - pass vertex_index to fragment shader
   0.818469181590804   965: WebGPU Sprite Multiple - single,double,triple buffered - one vertex buffer, update verts
   0.8144527815247078  640: Three.js CSS + WebGL
   0.8111271555770427 1006: WebGPU One 2D texture with 8 layers and only "2d" views
=> 0.8111271555770427  975: WebGPU Points with size and texture and color, rotation, and (mips)
=> 0.8111271555770427  963: WebGPU Sprite Multiple - one vertex buffer, update verts, + color
=> 0.8032939967570338 1020: WebGPU Vertex Buffer vertices - instanced colors with edge texture
   0.8032939967570338  961: WebGPU test storage buffer write from fragment shader using atomic
   0.8007162113952138  985: WebGL 8 color attachments render targets
   0.7938839309316525 1045: WebGPU: Compat with validation - generate mipmap (validation compatible)
   0.7938839309316525 1040: WebGPU: generate mipmap comparison (as cube vs as 2d)
   0.7938839309316525 1039: WebGPU: generate mipmap comparison (as cube vs as 2d)
   0.7938839309316525 1038: WebGPU: generate mipmap comparison (as cube vs as 2d)
   0.7938839309316525 1037: WebGPU: generate mipmap comparison (as cube vs as 2d)
   0.7938839309316525  983: WebGPU Compute Shader num F16 values 0 to 1
   0.7938839309316525  974: WebGPU Simple Textured Quad Mipmap (use views with mips)
   0.7938839309316525  966: WebGPU Sprite Multiple - single,double,triple buffered - bindGroup per
   0.7938839309316525  559: WebGPU Texture Upload (uploads 500, 256x256 textures, with mips)
   0.7858955088163471  430: Safari WebGL Alpha: false issue
   0.7824117817365114 1047: WebGPU with Canvas 2D on top - sync
   0.7824117817365114 1012: WebGPU draw to texture and keep contents (multi-sampled)
=> 0.7824117817365114  957: WebGPU Points with size and texture and color
   0.7824117817365114  956: WebGPU Simple Triangle - write to storage buffer
   0.7824117817365114  953: WebGPU Multiple Triangles w/split Storage Buffers (explicit bindGroupLayout)
   0.7824117817365114  932: WebGPU Cube Multiple (with a renderbundle per object)
   0.7824117817365114  904: WebGPU Cube (with vec4 + f32 vertex buffer)
   0.7824117817365114  530: WebGPU - Picking - GPU (vs SVG hover)
   0.7695036100804312 1044: WebGPU: Compat with validation - generate mipmap
   0.7695036100804312 1036: WebGPU sample center of 2x2 cube face
   0.7695036100804312 1018: WebGPU load an HTMLImageElement (needs Chrome 118)
   0.7695036100804312 1017: WebGPU Cube with atomicAdd in fragment shader
   0.7695036100804312 1010: WebGPU draw to texture and keep contents
   0.7695036100804312 1004: WebGPU Simple Textured Quad (float16 / rgba16float)
   0.7695036100804312  970: WebGPU endless loop - look at ascii
   0.7695036100804312  950: WebGPU: memory - shader module (1 shader)
   0.7695036100804312  947: WebGPU Simple Textured Quad MipFilter - issue
   0.7695036100804312  813: WebGPU Test copying the canvas via drawImage 
   0.7536674547791905  999: WebGPU: bindGroup buffer size error test
   0.7536674547791905  981: WebGPU Simple Textured Quads - Text
   0.7536674547791905  910: WebGPU Cube (with F + normal)
   0.7536674547791905  832: WebGPU Cube - Pulling Vertices (indexed)
   0.7536674547791905  831: WebGPU Cube - Pulling Vertices (Firefox)
   0.7536674547791905  830: WebGPU hello triangle via uniform array
   0.7536674547791905  821: WebGPU Multiple Views simulating Multiple Canvases
   0.7536674547791905  672: Check WebGL Floating Point Format/Type Combo
   0.7483314773547883  218: How much WebGL work
   0.7483314773547883  215: How much WebGL work
   0.7483314773547883  107: How much WebGL work
   0.7461009761866464  268: Floating point color textures.
   0.7461009761866464  257: Floating point color textures.
   0.7435814382489114  597: Copy of Raw WebGPU article (no indices)
=> 0.7435814382489114  596: Copy of Raw WebGPU article (no color)
   0.7399346708189991  584: DUAL - GPU
   0.7399346708189991  482: Bug in WebGL2
   0.7335666720836618 1034: WebGPU auto generated GPUBindGroupLayout message
   0.7335666720836618  987: WebGPU Render bc1-rgba-unorm to rgba8unorm
   0.7335666720836618  960: WebGPU textureLoad with mips (rgb9e5ufloat)
   0.7335666720836618  949: WebGPU: memory - shader module
   0.7335666720836618  934: WebGPU: memory - example 2
   0.7335666720836618  928: WebGPU: Triangle in Clip Space
   0.7335666720836618  906: WebGPU: request features and limits
   0.7335666720836618  894: WebGPU: Test Depth Store test
   0.7335666720836618  858: WebGPU: Test maxBindingGroups and maxBindingsPerBindGroup
   0.7335666720836618  833: WebGPU Cube - Pulling Vertices
   0.7335666720836618  822: WebGPU Multiple Canvases (Intersection Observer)
   0.7335666720836618  560: WebGPU Cube (pause on resize)
   0.7335666720836618  491: WebGPU 2 Cubes (stride 0)
   0.7335666720836618  490: WebGPU Cube - with copy
   0.7327131571339673  632: show debug shader
   0.7327131571339673  432: Test WebGL CORS
   0.7263007948981333  865: WebGL and WebGPU devtool console messages
   0.7211102550927979   17: WebGL2 WEBGL_draw_buffers state test
   0.7071067811865476 1043: WebGPU: cube map test
   0.7071067811865476 1029: WebGPU: Indexing interleaved f32s
   0.7071067811865476 1028: WebGPU Depth Only Render
   0.7071067811865476 1022: WebGPU Cube w/3d texture
   0.7071067811865476 1013: WebGPU clip space coordinatees
   0.7071067811865476 1011: WebGPU 2 multisample pipelines
   0.7071067811865476  978: WebGPU Multiple Canvases (2k)
   0.7071067811865476  969: WebGPU textureLoad with mips
   0.7071067811865476  959: WebGPU Points with size
   0.7071067811865476  955: WebGPU: Compute shader basics
   0.7071067811865476  933: WebGPU: Mask via Stencil
   0.7071067811865476  908: WebGPU: Quad (with F)
   0.7071067811865476  892: WebGPU dpdx dpdy normals
   0.7071067811865476  876: WebGPU vs WebGL: FragCoord
   0.7071067811865476  867: WebGPU check limit requests
   0.7071067811865476  851: WebGPU canvas2d drawImage order
   0.7071067811865476  838: WebGPU small and simple
   0.7071067811865476  837: WebGPU \0 in shader
   0.7071067811865476  812: WebGPU 0 in labels
   0.7071067811865476  798: WebGPU Render with rgba8unorm
   0.7071067811865476  795: WebGPU Cube with transparency 
   0.7071067811865476  521: WebGPU: Simple Compute Shader
   0.7071067811865476  415: Check WebGLObjects in workers
   0.7044349461747377  598: Copy of Raw WebGPU article
   0.6996386826511016  676: Color Points Facing Away vs Forward
   0.6856996523489355  507: WebGL: WEBGL_debug_shaders getTranslatedShaderSource
   0.6703562957901678 1046: WebGPU Cube w/Timing
   0.6703562957901678 1002: WebGPU: executeBundles test
   0.6703562957901678  994: WebGPU canvas import
   0.6703562957901678  905: WebGPU const math
   0.6703562957901678  903: WebGPU endless loop
   0.6703562957901678  895: WebGPU: Draw Quads
   0.6703562957901678  877: WebGPU: ShaderToy (https://www.shadertoy.com/view/DlBXW1)
   0.6703562957901678  862: WebGPU: Destroy Device
   0.6703562957901678  861: WebGPU Throttling Issue
   0.6703562957901678  829: WebGPU padding test
   0.6703562957901678  824: WebGPU Multiple Canvases
   0.6703562957901678  793: WebGPU pow(negative, positive)
   0.6703562957901678  595: WebGPU fragCoord quad
   0.6703562957901678  418: Show WebGL2 extensions
   0.6703562957901678   85: Show WebGL extensions
   0.6599828249185699  976: WebGPU Cube (webgpu-utils)
   0.6468482211944342  984: Virtual WebGL2
   0.612592665952338   958: WebGPU Points
   0.612592665952338   923: WebGPU-Memory Example
   0.612592665952338   916: WebGPU: captureStream
   0.612592665952338   912: WebGPU: Quad
   0.612592665952338   863: WebGPU: SDF
   0.612592665952338   603: check WebGL_multi_draw
   0.612592665952338   542: WebGPU Cube
   0.612592665952338   145: Check WEBGL_DrawBuffers

Additional context

The linked jsfiddle does a simple filter for entries that have the words "color" and "webgpu" (case insensitive). It finds 5 entries. Those entries are no where near highest scores of the fuse results.

Maybe I'm using it wrong or maybe I don't understand what this library is supposed to do?

JEK58 commented 7 months ago

I noticed the same when searching for names.

"John Doe" matches "John Doe"

But if the name is in reversed order:

"Doe John" matches "Doe Smith"

Which doesn't make too much sense.

greggman commented 7 months ago

I ended up using "minisearch". It's possible I just didn't configure Fuse correctly though.

====[ minisearch ] =========

=>  17.50778137835728 WebGPU Points with size and texture and color
=> 16.794186897155022 Copy of Raw WebGPU article (no color)
=> 15.614913036410263 WebGPU Sprite Multiple - one vertex buffer, update verts, + color
=> 15.614913036410263 WebGPU Points with size and texture and color, rotation, and (mips)
=> 10.455952247922246 WebGPU Vertex Buffer vertices - instanced colors with edge texture
    7.046643923518333 CSS Relative Color
    6.247157089843079 Check Framebuffer Attachment Color Encoding
    6.247157089843079 Floating point color textures.
    6.247157089843079 Floating point color textures.
    5.937783199077046 Simple CSS to 32bit color conversion
    5.937783199077046 Color Points Facing Away vs Forward
    5.937783199077046 WebGL 8 color attachments render targets
    5.440594521071296 WebGL globe only shows color for first dataset
    5.058560490790414 WebGL Sprite Multiple - one vertex buffer, update verts, + color
    4.306472176379028 Draw a Texture where every mip color and we select them with TEXTURE_BASE_LEVEL and TEXTURE_MAX_LEVEL
     4.27174440631764 WebGPU Cube (webgpu-utils)
    4.116773772922422 WebGPU Cube
    4.116773772922422 WebGPU: SDF
    4.116773772922422 WebGPU: Quad
    4.116773772922422 WebGPU: captureStream
    4.116773772922422 WebGPU Points
   3.8292497486649437 WebGPU fragCoord quad
   3.8292497486649437 WebGPU Multiple Canvases
   3.8292497486649437 WebGPU padding test
   3.8292497486649437 WebGPU Throttling Issue
   3.8292497486649437 WebGPU: Destroy Device
   3.8292497486649437 WebGPU: Draw Quads
   3.8292497486649437 WebGPU endless loop
   3.8292497486649437 WebGPU const math
   3.8292497486649437 WebGPU-Memory Example
   3.8292497486649437 WebGPU canvas import
   3.8292497486649437 WebGPU: executeBundles test
     3.59274906137481 WebGPU Cube - with copy
     3.59274906137481 WebGPU: Simple Compute Shader
     3.59274906137481 WebGPU Render with rgba8unorm
     3.59274906137481 WebGPU 0 in labels
     3.59274906137481 WebGPU Cube - Pulling Vertices
     3.59274906137481 WebGPU \0 in shader
     3.59274906137481 WebGPU small and simple
     3.59274906137481 WebGPU canvas2d drawImage order
     3.59274906137481 WebGPU check limit requests
     3.59274906137481 WebGPU vs WebGL: FragCoord
     3.59274906137481 WebGPU dpdx dpdy normals
     3.59274906137481 WebGPU: Mask via Stencil
     3.59274906137481 WebGPU: memory - example 2
     3.59274906137481 WebGPU: memory - shader module
     3.59274906137481 WebGPU: Compute shader basics
     3.59274906137481 WebGPU Points with size
     3.59274906137481 WebGPU textureLoad with mips
     3.59274906137481 WebGPU 2 multisample pipelines
     3.59274906137481 WebGPU clip space coordinatees
     3.59274906137481 WebGPU Depth Only Render
     3.59274906137481 WebGPU: Indexing interleaved f32s
     3.59274906137481 WebGPU: cube map test
     3.59274906137481 WebGPU Cube w/Timing
    3.394796867245139 Copy of Raw WebGPU article
    3.394796867245139 WebGPU pow(negative, positive)
    3.394796867245139 WebGPU Cube with transparency 
    3.394796867245139 WebGPU Multiple Views simulating Multiple Canvases
    3.394796867245139 WebGPU: Test maxBindingGroups and maxBindingsPerBindGroup
    3.394796867245139 WebGPU: Test Depth Store test
    3.394796867245139 WebGPU: request features and limits
    3.394796867245139 WebGPU: Quad (with F)
    3.394796867245139 WebGPU: Triangle in Clip Space
    3.394796867245139 WebGPU Multiple Canvases (2k)
    3.394796867245139 WebGPU Simple Textured Quads - Text
    3.394796867245139 WebGPU Cube w/3d texture
    3.394796867245139 WebGPU auto generated GPUBindGroupLayout message
    3.226678553574504 WebGPU 2 Cubes (stride 0)
    3.226678553574504 WebGPU Cube (pause on resize)
    3.226678553574504 WebGPU Multiple Canvases (Intersection Observer)
    3.226678553574504 WebGPU hello triangle via uniform array
    3.226678553574504 WebGPU Cube - Pulling Vertices (Firefox)
    3.226678553574504 WebGPU Cube - Pulling Vertices (indexed)
    3.226678553574504 WebGL and WebGPU devtool console messages
    3.226678553574504 WebGPU Simple Textured Quad MipFilter - issue
    3.226678553574504 WebGPU: memory - shader module (1 shader)
    3.226678553574504 WebGPU textureLoad with mips (rgb9e5ufloat)
    3.226678553574504 WebGPU endless loop - look at ascii
    3.226678553574504 WebGPU: bindGroup buffer size error test
    3.226678553574504 WebGPU: Compat with validation - generate mipmap
   3.2041276265298784 Test illegal colors
    3.082122235813342 WebGPU - Picking - GPU (vs SVG hover)
    3.082122235813342 WebGPU Cube (with F + normal)
    3.082122235813342 WebGPU Simple Triangle - write to storage buffer
    3.082122235813342 WebGPU Render bc1-rgba-unorm to rgba8unorm
    3.082122235813342 WebGPU Simple Textured Quad (float16 / rgba16float)
    3.082122235813342 WebGPU draw to texture and keep contents
    3.082122235813342 WebGPU Cube with atomicAdd in fragment shader
    3.082122235813342 WebGPU sample center of 2x2 cube face
    3.082122235813342 WebGPU with Canvas 2D on top - sync
   3.0062354973722494 Draw in multiple colors
    2.956498927506214 Copy of Raw WebGPU article (no indices)
    2.956498927506214 WebGPU Test copying the canvas via drawImage 
    2.956498927506214 WebGPU load an HTMLImageElement (needs Chrome 118)
    2.956498927506214 WebGPU: Compat with validation - generate mipmap (validation compatible)
   2.8463176637312073 WebGPU: ShaderToy (https://www.shadertoy.com/view/DlBXW1)
   2.8463176637312073 WebGPU Cube (with vec4 + f32 vertex buffer)
   2.8463176637312073 WebGPU Cube Multiple (with a renderbundle per object)
   2.8463176637312073 WebGPU Sprite Multiple - single,double,triple buffered - bindGroup per
   2.8463176637312073 Canvas with size 0 in WebGL, WebGPU, and Canvas2D
   2.8463176637312073 WebGPU Compute Shader num F16 values 0 to 1
   2.8463176637312073 WebGPU: generate mipmap comparison (as cube vs as 2d)
   2.8463176637312073 WebGPU: generate mipmap comparison (as cube vs as 2d)
   2.8463176637312073 WebGPU: generate mipmap comparison (as cube vs as 2d)
   2.8463176637312073 WebGPU: generate mipmap comparison (as cube vs as 2d)
    2.748896027414718 WebGPU Texture Upload (uploads 500, 256x256 textures, with mips)
    2.748896027414718 WebGPU Multiple Triangles w/split Storage Buffers (explicit bindGroupLayout)
    2.748896027414718 WebGPU test storage buffer write from fragment shader using atomic
    2.748896027414718 WebGPU Simple Textured Quad Mipmap (use views with mips)
    2.748896027414718 WebGPU draw to texture and keep contents (multi-sampled)
   2.7308511057662863 Canvas2D colorSpace srgb vs display-p3
    2.662138875439085 WebGPU One 2D texture with 8 layers and only "2d" views
    2.608508029550573 Canvas2D colorSpace srgb vs display-p3 conversion
   2.5843859606010224 WebGPU Sprite Multiple - single,double,triple buffered - one vertex buffer, update verts
   2.5789681144601846 solid colors three.js by calling toNonIndexed
    2.450812948206141 WebGPU Simple Inter-Stage Variables by fn param - pass vertex_index to fragment shader
github-actions[bot] commented 3 months ago

This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 30 days