@@ -14,29 +14,33 @@ function tripal_elasticsearch_advanced_search_form($form, &$form_state) {
1414 $ bundles = [];
1515 }
1616
17+ $ form_vals = $ form_state ['values ' ] ?? [];
18+
19+ $ values = [
20+ 'term ' => trim ($ _GET ['term ' ] ?? $ form_vals ['term ' ] ?? '' ),
21+ 'category ' => $ _GET ['category ' ] ?? $ form_vals ['category ' ] ?? '' ,
22+ 'field ' => $ _GET ['field ' ] ?? $ form_vals ['field ' ] ?? '' ,
23+ ];
24+
1725 $ helper = new \ES \Common \BundleHelper ();
1826
1927 $ form ['wrapper ' ] = [
20- '#prefix ' => '<div id="advanced_search_wrapper" class="container-inline" > ' ,
28+ '#prefix ' => '<div id="advanced_search_wrapper"> ' ,
2129 '#suffix ' => '</div> ' ,
2230 ];
2331
24- $ category = trim (
25- $ _GET ['category ' ] ?? $ form_state ['values ' ]['category ' ] ?? ''
26- );
27-
2832 $ form ['wrapper ' ]['category ' ] = [
2933 '#type ' => 'select ' ,
3034 '#options ' => ['' => 'Any Category ' ] + $ bundles ,
3135 '#ajax ' => [
3236 'callback ' => 'tripal_elasticsearch_advanced_search_form_callback ' ,
3337 'wrapper ' => 'advanced_search_wrapper ' ,
3438 ],
35- '#default_value ' => $ category ,
39+ '#default_value ' => $ values [ ' category ' ] ,
3640 ];
3741
38- if (!empty ($ category )) {
39- $ fields = $ helper ->getFieldsByBundle ($ helper ->getBundleByName ($ category ));
42+ if (!empty ($ values [ ' category ' ] )) {
43+ $ fields = $ helper ->getFieldsByBundle ($ helper ->getBundleByName ($ values [ ' category ' ] ));
4044 $ field_options = [
4145 '' => 'Any Field ' ,
4246 ];
@@ -48,13 +52,13 @@ function tripal_elasticsearch_advanced_search_form($form, &$form_state) {
4852 $ form ['wrapper ' ]['field ' ] = [
4953 '#type ' => 'select ' ,
5054 '#options ' => $ field_options ,
51- '#default_value ' => trim ( $ _GET ['field ' ] ?? '' ) ,
55+ '#default_value ' => $ values ['field ' ],
5256 ];
5357 }
5458
5559 $ form ['wrapper ' ]['term ' ] = [
5660 '#type ' => 'textfield ' ,
57- '#default_value ' => $ _GET ['term ' ] ?? '' ,
61+ '#default_value ' => $ values ['term ' ],
5862 ];
5963
6064 $ form ['wrapper ' ]['submit ' ] = [
@@ -64,11 +68,9 @@ function tripal_elasticsearch_advanced_search_form($form, &$form_state) {
6468
6569 $ form ['#method ' ] = 'GET ' ;
6670
67- //if (isset($_GET['term']) && !empty($_GET['term'])) {
6871 $ form ['wrapper ' ]['results ' ] = [
69- '#markup ' => tripal_elasticsearch_advanced_search_results ($ _GET ),
72+ '#markup ' => tripal_elasticsearch_advanced_search_results ($ values ),
7073 ];
71- //}
7274
7375 return $ form ;
7476}
@@ -86,7 +88,7 @@ function tripal_elasticsearch_advanced_search_results(array $values) {
8688 try {
8789 $ instance = new \ES \Common \Instance ();
8890 $ results = tripal_elasticsearch_perform_advanced_search ($ values , 15 );
89- if ($ results ['total ' ] == 0 && !empty ($ values ['term ' ])) {
91+ if ($ results ['total ' ] == 0 && !empty ($ values ['term ' ])) {
9092 $ values ['term ' ] = strtolower ($ values ['term ' ]);
9193 $ results = tripal_elasticsearch_perform_advanced_search ($ values , 15 );
9294 }
@@ -101,13 +103,19 @@ function tripal_elasticsearch_advanced_search_results(array $values) {
101103 );
102104 }
103105
104- $ content = theme ('elasticsearch_results_header ' , [
105- 'page ' => $ results ['page ' ],
106- 'total ' => $ results ['total ' ],
107- 'pages ' => $ results ['pages ' ],
108- 'time ' => $ results ['time ' ]
109- ]);
110- $ content .= tripal_elasticsearch_get_website_search_result_table ($ hits , false );
106+ $ content = theme (
107+ 'elasticsearch_results_header ' ,
108+ [
109+ 'page ' => $ results ['page ' ],
110+ 'total ' => $ results ['total ' ],
111+ 'pages ' => $ results ['pages ' ],
112+ 'time ' => $ results ['time ' ],
113+ ]
114+ );
115+ $ content .= tripal_elasticsearch_get_website_search_result_table (
116+ $ hits ,
117+ FALSE
118+ );
111119 $ content .= $ results ['pager ' ];
112120
113121 return $ content ;
0 commit comments