diff --git a/app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb b/app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb
index 1c3687f..db3772c 100644
--- a/app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb
+++ b/app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb
@@ -11,7 +11,7 @@
<%= label_tag :subjects %>
- <%= select_tag "subject_ids[]", options_from_collection_for_select(subjects, :id, :lineage_name, doctrine.subject_ids), class: "form-select subject-ids-selectize", multiple: true, prompt: "Please select" %>
+ <%= select_tag "subject_ids[]", options_from_collection_for_select(subjects.sort_by { |sub| sub.lineage_name }, :id, :lineage_name, doctrine.subject_ids), class: "form-select subject-ids-selectize", multiple: true, prompt: "Please select" %>
diff --git a/app/controllers/api/subjects_controller.rb b/app/controllers/api/subjects_controller.rb
new file mode 100644
index 0000000..6a12bde
--- /dev/null
+++ b/app/controllers/api/subjects_controller.rb
@@ -0,0 +1,21 @@
+module Api
+ class SubjectsController < BaseController
+ include SubjectSearch
+
+ authorize_resource :doctrine, class: "Cdao::Subject", only: %i[index]
+
+ def index
+ @search = search_subject(search_params)
+
+ @subjects = @search.results
+
+ respond_with @subjects
+ end
+
+ private
+ def search_params
+ params.permit(:name, :parent_id, :state, doctrine_ids: [], exclude_ids: [])
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/app/controllers/concerns/subject_search.rb b/app/controllers/concerns/subject_search.rb
new file mode 100644
index 0000000..947d2ba
--- /dev/null
+++ b/app/controllers/concerns/subject_search.rb
@@ -0,0 +1,26 @@
+module SubjectSearch
+ def search_subject(search_params)
+ fulltext_fields = %i[name lineage_name].freeze
+
+ search = ::Cdao::Subject.search do
+ fulltext search_params[:q], fields: fulltext_fields if search_params[:q].present?
+
+ fulltext_fields.each do |field|
+ fulltext search_params[field], fields: %i[field], query_phrase_slop: 0, minimum_match: 1
+ end
+
+ with :parent_id, search_params[:parent_id].to_i if search_params[:parent_id].present?
+
+ without :parent_id if search_params[:is_root].present? && search_params[:is_root].to_s.eql?("true")
+
+ without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present?
+
+ order_by :lineage_name, :asc
+ order_by :name, :asc
+
+ paginate page: search_params[:page] || 1, per_page: search_params[:per_page] || 20
+ end
+
+ search
+ end
+end
diff --git a/app/javascript/controllers/document_controller.js b/app/javascript/controllers/document_controller.js
index 9fc6119..48d58fb 100644
--- a/app/javascript/controllers/document_controller.js
+++ b/app/javascript/controllers/document_controller.js
@@ -19,7 +19,7 @@ export default class extends ApplicationController {
modalDocumentSearch () {
var $this = this
- $.get("/api/jurisprudences.json", { q: $this.inputTarget.value }, function (data, status) {
+ $.get("/api/documents.json", { q: $this.inputTarget.value }, function (data, status) {
if (status === "success") {
$this.stimulate("DocumentReflex#render_modal_document_search_table", data)
}
diff --git a/app/models/cdao/subject.rb b/app/models/cdao/subject.rb
index 86d5e14..a6b8270 100644
--- a/app/models/cdao/subject.rb
+++ b/app/models/cdao/subject.rb
@@ -55,7 +55,15 @@ class Cdao::Subject < Cdao::Base
text :name
+ text :lineage_name do
+ lineage_name
+ end
+
string :name
string :state
+
+ string :lineage_name do
+ lineage_name
+ end
end
end
diff --git a/app/views/api/subjects/index.json.jbuilder b/app/views/api/subjects/index.json.jbuilder
new file mode 100644
index 0000000..053ede2
--- /dev/null
+++ b/app/views/api/subjects/index.json.jbuilder
@@ -0,0 +1,4 @@
+json.array!(@subjects) do |subject|
+ json.extract! subject, *%i[id name parent_id state doctrine_ids created_at updated_at]
+ json.text [subject.lineage_name].join(" - ")
+end