laravel-search-string

🔍 Generates database queries based on one unique string

MIT License

Downloads
317.9K
Stars
773
Committers
8
laravel-search-string - v1.3.0 Latest Release

Published by lorisleiva over 1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/lorisleiva/laravel-search-string/compare/v1.2.0...v1.3.0

laravel-search-string - v1.2.0

Published by lorisleiva over 2 years ago

laravel-search-string - v1.1.3

Published by lorisleiva over 3 years ago

Make order by and select keyword rules use column aliases (See #34)

laravel-search-string - v1.1.2

Published by lorisleiva over 3 years ago

Add case_insensitive option for search queries — defaults to false for backward compatibility. (See #22)

You can set it to true in your options amongst columns and keywords. For example, in the config/search-string.php file:

return [
    'default' => [
        'case_insensitive' => true, // <- Globally.
        // ...
    ],

    Article::class => [
        'case_insensitive' => true, // <- Only for the Article class.
        // ...
    ],
];

When set to true, it will lowercase both the column and the value before comparing them using the like operator.

$value = mb_strtolower($value, 'UTF8');
$query->whereRaw("LOWER($column) LIKE ?", ["%$value%"]);
laravel-search-string - v1.1.1

Published by lorisleiva over 3 years ago

  • More robust way to check if a string is a regex (#31)
  • Do not qualify the column name when already prefixed (#33)
laravel-search-string - v1.1.0

Published by lorisleiva over 3 years ago

Use qualify column names to avoid ambiguous conflicts (See #32)

laravel-search-string - v1.0.4

Published by lorisleiva about 4 years ago

🚑 Fix searchable columns inside relationships (#27)

laravel-search-string - v1.0.3

Published by lorisleiva about 4 years ago

⬆️ Add support for Laravel 8

laravel-search-string - v1.0.2

Published by lorisleiva about 4 years ago

Fix resolve conflict with HOA protocol

laravel-search-string - v1.0.1

Published by lorisleiva over 4 years ago

🚑 Allow CompilerInterface to handle null input instead of throwing a TypeError (#20).

laravel-search-string - v1.0.0

Published by lorisleiva over 4 years ago

What's new?

💍 Relationships are here! (documentation)

You can now query a model's relationships. For example:

  • comments > 3
  • comments (equivalent to comments > 0)
  • category.name: Laravel
  • category: (name: Laravel or name: Vuejs)
  • comments: (author: (name: johndoe))
  • comments.author.name: johndoe

✨ New artisan commands

Three artisan commands have been added allowing you to play with the search string syntax.

  • php artisan search-string:ast <model> <query>: Dumps the tree (AST) generated by the query.
  • php artisan search-string:sql <model> <query>: Dumps the SQL generated by the query.
  • php artisan search-string:get <model> <query>: Returns the results generated by the query.

For example: php artisan search-string:sql User "name = John"

💡 Full re-write of the compiler

The entire parser has been re-written using an Llk compiler compiler (from HOA).

This allows us to define the entire syntax as a grammar that itself gets compiled into a compiler (you can see the grammar here if that's your type of thing). As a result, the generated parser is a lot more robust and more test have been written to make sure of that. Additionally, it makes the parser easier to maintain and to add new features.

Breaking changes

  • The biggest breaking changes you might come across is the removal of operator and value for the column options. Matching operators was a pointless task since they were hardcoded in the search string syntax and matching the value became redundant when adding the map column option (which I am planning on making more flexible in the future).
  • Additionally, because the implementation of the parser has changed and became more robust, you might find that some invalid strings that were not failing in the past will now fail as expected.
laravel-search-string - v0.1.6

Published by lorisleiva over 4 years ago

Add value mapping. You can now add a map to your column options that will transform any value entered by the user into something that your database understands.

// With these column options...
protected $searchStringColumns = [
    'support_level_id' => [
        'key' => 'support_level',
        'map' => [
            'testing' => 0,
            'community' => 1,
            'official' => 2,
        ]
    ],
];

// "support_level:testing" will generate:
$query->where('support_level_id', '=', 0);

// "support_level:another_value" will generate:
$query->where('support_level_id', '=', 'another_value');

As you can see from that last example, if a user enters a value which is missing from the map option, it will simply be passed as-is. This makes it possible to use the map option as a way to define value aliases.

If you'd like to ensure that any value missing from that mapping generates an InvalidSearchStringException, then you should adjust the value option accordingly. Here is what that would like for our example above.

protected $searchStringColumns = [
    'support_level_id' => [
        'key' => 'support_level',
        'value' => '^testing|community|official$' // <= Whitelist your option using a regex
        'map' => [
            'testing' => 0,
            'community' => 1,
            'official' => 2,
        ]
    ],
];
laravel-search-string - v0.1.5

Published by lorisleiva over 4 years ago

⬆️ Add support for Laravel 7

laravel-search-string - v0.1.4

Published by lorisleiva about 5 years ago

⬆️ Add support for Laravel 6

laravel-search-string - v0.1.3

Published by lorisleiva over 5 years ago

🚑 Fixes column aliases (#3)

laravel-search-string - v0.1.2

Published by lorisleiva over 5 years ago

🚑 Support versions greater than 5.8.0 (#2)

laravel-search-string - v0.1.1

Published by lorisleiva over 5 years ago

⬆️ Support Laravel 5.7 and 5.8

laravel-search-string - First release 🎉

Published by lorisleiva over 6 years ago