loilo / Fuse

šŸ” Fuzzy search for PHP, ported from Fuse.js
Apache License 2.0
320 stars 30 forks source link

What's Wrong With My Array? #4

Closed teamcoltra closed 6 years ago

teamcoltra commented 6 years ago

I have an array that outputs like this:

    [1106] => Array
        (
            [id] => 1106
            [url] => 3-brides-for-3-bad-boys-160488
            [description] => 0
            [title] => 3 Brides for 3 Bad Boys
            [author] => 3 Brides for 3 Bad Boys (mf)
            [author_lname] => Boys
            [language] => en
        )

    [1107] => Array
        (
            [id] => 1107
            [url] => 3-brisingr-3-12630502066281
            [description] => 0
            [title] => 3-Brisingr-3
            [author] => Unknown
            [author_lname] => 
            [language] => eng
        )

    [1108] => Array
        (
            [id] => 1108
            [url] => 3-claus-of-death-120101
            [description] => 0
            [title] => 3 Claus of Death
            [author] => Gayle Trent
            [author_lname] => Trent
            [language] => en
        )

But that results in:

PHP Notice: Undefined offset: -1 in /var/www/search/vendor/loilo/fuse/src/Bitap/matched_indices.php on line 24 PHP Notice: Undefined offset: -1 in /var/www/search/vendor/loilo/fuse/src/Bitap/matched_indices.php on line 24 PHP Notice: Undefined offset: -1 in /var/www/search/vendor/loilo/fuse/src/Bitap/matched_indices.php on line 24 PHP Notice: Undefined offset: -1 in /var/www/search/vendor/loilo/fuse/src/Bitap/matched_indices.php on line 24 PHP Notice: Undefined offset: -1 in /var/www/search/vendor/loilo/fuse/src/Bitap/matched_indices.php on line 24 PHP Notice: Undefined offset: -1 in /var/www/search/vendor/loilo/fuse/src/Bitap/matched_indices.php on line 24 PHP Notice: Undefined offset: -1 in /var/www/search/vendor/loilo/fuse/src/Bitap/matched_indices.php on line 24 PHP Notice: Undefined offset: -1 in /var/www/search/vendor/loilo/fuse/src/Bitap/matched_indices.php on line 24 PHP Notice: Undefined offset: -1 in /var/www/search/vendor/loilo/fuse/src/Bitap/matched_indices.php on line 24 PHP Notice: Undefined offset: -1 in /var/www/search/vendor/loilo/fuse/src/Bitap/matched_indices.php on line 24

I was wondering what I need to do to? I have tried putting my array into a parent array but that changes everything to:

/var/www/search# php search.php PHP Notice: Undefined offset: 0 in /var/www/search/vendor/loilo/fuse/src/Fuse.php on line 97 PHP Notice: Undefined offset: 0 in /var/www/search/vendor/loilo/fuse/src/Fuse.php on line 123

loilo commented 6 years ago

That seems to be an incorrectly ported piece of code by me.

Do you still get a result when using the search, despite the error message?

teamcoltra commented 6 years ago

Right now my options are barebones:

$fuse = new \Fuse\Fuse($new, [
  "keys" => [ "title", "author" ]]);
teamcoltra commented 6 years ago

No results

loilo commented 6 years ago

Do you get any results when performing the same search in Fuse.js?

teamcoltra commented 6 years ago

I just used their web demo and it works fine when I use json or my array.

loilo commented 6 years ago

Hm. It's hard for to reproduce the error without having the whole dataset and the search query.

I know how the PHP Notice message emerges and how to avoid that, but you should still get a result...

teamcoltra commented 6 years ago

json file = https://pastebin.ca/3957763

require_once 'vendor/autoload.php';
$json = file_get_contents('jason.txt');
$decoded = json_decode($json,true);

$fuse = new \Fuse\Fuse($decoded, [
  "keys" => [ "title", "author" ]]);

$fuse->search('doc');
loilo commented 6 years ago

Thanks, I'll take a look. šŸ‘

teamcoltra commented 6 years ago

I feel like I have found part of the issue, which is just me being dumb and not print_r($fuse->search('doc')); that's why I'm not getting any results.

facepalm

So if you already know the reason for the generated errors I think we solved it.

loilo commented 6 years ago

Great. Was just about to say, I'm not having any issues with getting results from your code & data. šŸ™ˆ

teamcoltra commented 6 years ago

The problem is the actual full sized json file is ~30MB large, https://github.com/robotomize/fujes handles it pretty quickly but this really chugs at it. That's not a complaint against the system, I don't think my use case is typical. That's probably a bit why I am having more of these issues.

loilo commented 6 years ago

Possibly. I'm not very deep into the CS-related details on the algorithm. After all, this library is just a port. :)

Btw, new version (3.2.2) is out. Your PHP notices should be gone with that. (And I really should turn mine on for library development. šŸ™ƒ )

loilo commented 6 years ago

If this solves your problem, feel free to close this issue. :)

teamcoltra commented 6 years ago

Yes it does, new update works great. Thanks Loilo!

loilo commented 6 years ago

My pleasure.