-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautocomplete.php
64 lines (50 loc) · 1.47 KB
/
autocomplete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
// Load WPML class
//WpSolrExtensions::load();
function wdm_return_solr_rows() {
if ( isset( $_POST['security'] )
&& wp_verify_nonce( $_POST['security'], 'nonce_for_autocomplete' )
) {
$input = isset( $_POST['word'] ) ? $_POST['word'] : '';
if ( '' != $input ) {
$input = strtolower( $input );
try {
$result = WPSOLR_Global::getSolrClient()->get_suggestions( $input );
echo json_encode( $result );
} catch ( Exception $e ) {
echo json_encode(
array(
'message' => htmlentities( $e->getMessage() )
)
);
}
}
}
die();
}
add_action( 'wp_ajax_wdm_return_solr_rows', 'wdm_return_solr_rows' );
add_action( 'wp_ajax_nopriv_wdm_return_solr_rows', 'wdm_return_solr_rows' );
function wdm_return_facet_solr_rows() {
if ( isset( $_POST['security'] )
&& wp_verify_nonce( $_POST['security'], 'nonce_for_autocomplete' )
) {
$input = isset( $_POST['word'] ) ? $_POST['word'] : '';
if ( '' != $input ) {
$input = strtolower( $input );
try {
$client = WPSolrSearchSolrClient::create_from_index_indice(null);
$result = $client->get_facet_suggestions( $input );
echo json_encode( $result );
} catch ( Exception $e ) {
echo json_encode(
array(
'message' => htmlentities( $e->getMessage() )
)
);
}
}
}
die();
}
add_action( 'wp_ajax_wdm_return_facet_solr_rows', 'wdm_return_facet_solr_rows' );
add_action( 'wp_ajax_nopriv_wdm_return_facet_solr_rows', 'wdm_return_facet_solr_rows' );