TipitakaWordParagraphController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Http\Controllers\V3;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\V3\IndexTipitakaWordParagraphRequest;
  5. use App\Http\Resources\V3\TipitakaWordParagraphResource;
  6. use App\Services\V3\TipitakaWordParagraphService;
  7. /**
  8. * 按词形找三藏段落(只读、公开)。
  9. *
  10. * 取代 `GET|POST /v2/search-pali-wbw`(`SearchPaliWbwController@index` / `@store`)。
  11. * v2 那份在 dashboard-v4 下线前原样保留,不要改动。
  12. */
  13. class TipitakaWordParagraphController extends Controller
  14. {
  15. public function __construct(private readonly TipitakaWordParagraphService $paragraphs) {}
  16. /**
  17. * 按词形找段落
  18. *
  19. * 在逐词表里精确匹配词形(连音已拆开),返回命中的段落,按命中权重降序、同分按经文顺序。
  20. * 词形先用 `GET /v3/pali-word-forms/{word}` 展开——拿词根直接查通常是 0 条。
  21. * 每条带整段正文(只含 `<b>` 黑体与 `<mark>` 命中词的安全 HTML)、章节路径与各印本页码。
  22. *
  23. * @unauthenticated
  24. *
  25. * @queryParam words string required 词形,逗号分隔,最多 200 个。Example: vitakko,vitakkaṃ
  26. * @queryParam bold string 只看黑体(only,注释书里被解释的词)或排除黑体(exclude);不给则不限。Enum: only,exclude
  27. * @queryParam book_id string 只看这些书,逗号分隔的 book_id(见 `/aggregate`)。Example: 75,79
  28. * @queryParam page integer 页码。Default: 1
  29. * @queryParam per_page integer 每页条数,上限 100。Default: 20
  30. */
  31. public function index(IndexTipitakaWordParagraphRequest $request)
  32. {
  33. return TipitakaWordParagraphResource::collection(
  34. $this->paragraphs->paragraphs($request->criteria(), (int) $request->validated('per_page', 20)),
  35. );
  36. }
  37. }