You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
4.0 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. Laravel 4+ Searchy
  2. ========================================
  3. ### Database Searching Made Easy
  4. Searchy is an easy-to-use Laravel 4+ package that makes running user driven searches on data in your models simple and effective.
  5. It uses pseudo fuzzy searching and other weighted mechanics depending on the search driver that you have enabled.
  6. It requires no other software installed on your server (so a bit slower than dedicated search programs) but can be setup and ready to go in minutes.
  7. Installation
  8. ----------------------------------------
  9. Add to your composer.json file under `require`:
  10. ```
  11. "tom-lingham/searchy" : "dev-master"
  12. ```
  13. Add the service provider to the `providers` array in Laravel's app/config/app.php file:
  14. ```
  15. 'TomLingham\Searchy\SearchyServiceProvider'
  16. ```
  17. Add the Alias to the `aliases` array in Laravel's app/config/app.php file:
  18. ```
  19. 'Searchy' => 'TomLingham\Searchy\SearchBuilder'
  20. ```
  21. Usage
  22. ----------------------------------------
  23. To use Searchy, you can take advantage of magic methods.
  24. If you are searching the name column/field of users in a `users` table you would, for example run:
  25. ```
  26. $users = Searchy::users('name')->query('John Smith');
  27. ```
  28. you can also write this as:
  29. ```
  30. $users = Searchy::search('users')->query('John Smith');
  31. ```
  32. These example both return a Laravel DB Query Builder Object, so you will need to chain `get()` to actually return the results in a usable object:
  33. ```
  34. $users = Searchy::search('users')->query('John Smith')->get();
  35. ```
  36. #### Searching multiple Columns
  37. You can also add multiple arguments ot the list fo fields/columns ot search by.
  38. For example, if you want to search the name, email address and username of a user, you might run:
  39. ```
  40. $users = Searchy::users('name', 'email', 'username')->query('John Smith');
  41. ```
  42. Configuration
  43. ----------------------------------------
  44. You can publish the configuration file to your `app` directory and override the settings by running `php artisan config:publish tom-lingham/searchy`
  45. You can set the default driver to use for searches in the configuration file. Your options (At this stage) are: `fuzzy`, `simple` and `levenshtein`.
  46. You can also override these methods using the following syntax when running a search:
  47. ```
  48. Searchy::driver('fuzzy')->users('name')->query('Bat Man')->get();
  49. ```
  50. Drivers
  51. ----------------------------------------
  52. Searchy takes advantage of 'Drivers' to handle matching various conditions of the fields you specify.
  53. Drivers are simply a specified group of 'Matchers' which match strings based on different conditions.
  54. Currently there are only three drivers: Simple, Fuzzy and Levenshtein (Experimental).
  55. Extending
  56. ----------------------------------------
  57. #### Drivers
  58. It's really easy to roll your own search drivers. Simply create a class that extends `TomLingham\Searchy\SearchDrivers\BaseSearchDriver` and add a property called `$matchers` with an array of matcher classes as the key and the multiplier for each matcher as the values. You can pick from the classes that are already included with Searchy or you can create your own.
  59. #### Matchers
  60. To create your own matchers, you can create your own class that extends `TomLingham\Searchy\Matchers\BaseMatcher` and (for simple Matchers) override the `formatQuery` method to return a string formatted with `%` wildcards in required locations. For more advanced extensions you may need to override the `buildQuery` method and others as well.
  61. Contributing & Reporting Bugs
  62. ----------------------------------------
  63. If you would like to improve on the code that is here, feel free to submit a pull request.
  64. If you find any bugs, submit them here and I will respond as soon as possible. Please make sure to include as much information as possible.
  65. Road Map
  66. ----------------------------------------
  67. To the future! The intention is to (eventually):
  68. 1. Remove Searchy's dependancy on Laravel
  69. 2. Include more drivers for more advanced searching (Including file system searching, indexing and more)
  70. 3. Implement an AJAX friendly interface for searching models and implementing autosuggestion features on the front end
  71. 4. Speed up search performance