TestSearchPali.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Tools\PaliSearch;
  4. use Illuminate\Console\Command;
  5. class TestSearchPali extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. * php artisan test:search.pali
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'test:search.pali {word?}';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command description';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return int
  33. */
  34. public function handle()
  35. {
  36. $word = $this->argument('word');
  37. if (empty($word)) {
  38. $word = 'citta';
  39. }
  40. $words = str_replace('_', ' ', $word);
  41. $words = explode(',', $words);
  42. $this->info("searching word={$word} limit=10,offset=0");
  43. $result = PaliSearch::search($words, [], 'case', 0, 10);
  44. if ($result) {
  45. $this->info("word={$word} total=".$result['total']);
  46. } else {
  47. $this->error("word={$word} search fail");
  48. }
  49. $rpc_result = PaliSearch::book_list($words,
  50. [],
  51. 'case');
  52. $this->info('book list count='.count($rpc_result['rows']));
  53. $this->info("searching word={$word} limit=10,offset=10");
  54. $result = PaliSearch::search($words, [], 'case', 10, 10);
  55. if ($result) {
  56. $this->info("word={$word} total=".$result['total']);
  57. } else {
  58. $this->error("word={$word} search fail");
  59. }
  60. $this->info("searching word={$word} book=267");
  61. $result = PaliSearch::search($words, [267], 'case', 0, 3);
  62. if ($result) {
  63. $this->info("word={$word} book=267 total=".$result['total']);
  64. } else {
  65. $this->error("word={$word} book=267 search fail");
  66. }
  67. return 0;
  68. }
  69. }