|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file provides an autocomplete service using the local data. |
|
4
|
|
|
* |
|
5
|
|
|
* @author David Riccitelli <[email protected]> |
|
6
|
|
|
* @since 3.24.2 |
|
7
|
|
|
* @package Wordlift\Autocomplete |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Wordlift\Autocomplete; |
|
11
|
|
|
|
|
12
|
|
|
use Wordlift_Entity_Service; |
|
13
|
|
|
use Wordlift_Post_Excerpt_Helper; |
|
14
|
|
|
|
|
15
|
|
|
class Local_Autocomplete_Service extends Abstract_Autocomplete_Service { |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @inheritDoc |
|
19
|
|
|
*/ |
|
20
|
|
|
public function query( $query, $scope, $excludes ) { |
|
21
|
|
|
|
|
22
|
|
|
$args = Wordlift_Entity_Service::add_criterias( array( |
|
23
|
|
|
'numberposts' => 50, |
|
24
|
|
|
'post_status' => 'any', |
|
25
|
|
|
's' => $query, |
|
26
|
|
|
'ignore_sticky_posts' => true, |
|
27
|
|
|
'suppress_filters' => true, |
|
28
|
|
|
) ); |
|
29
|
|
|
|
|
30
|
|
|
$posts = get_posts( $args ); |
|
31
|
|
|
|
|
32
|
|
|
$results = array_map( function ( $item ) { |
|
33
|
|
|
|
|
34
|
|
|
$entity_service = Wordlift_Entity_Service::get_instance(); |
|
35
|
|
|
$uri = $entity_service->get_uri( $item->ID ); |
|
36
|
|
|
|
|
37
|
|
|
return array( |
|
38
|
|
|
'id' => $uri, |
|
39
|
|
|
'label' => array( $item->post_title ), |
|
40
|
|
|
'labels' => $entity_service->get_alternative_labels( $item->ID ), |
|
41
|
|
|
'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $item ) ), |
|
42
|
|
|
'scope' => 'local', |
|
43
|
|
|
'sameAss' => get_post_meta( $item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS ), |
|
44
|
|
|
// The following properties are less relevant because we're linking entities that exist already in the |
|
45
|
|
|
// vocabulary. That's why we don't make an effort to load the real data. |
|
46
|
|
|
'types' => array( 'http://schema.org/Thing' ), |
|
47
|
|
|
'urls' => array(), |
|
48
|
|
|
'images' => array(), |
|
49
|
|
|
); |
|
50
|
|
|
}, $posts ); |
|
51
|
|
|
|
|
52
|
|
|
return $this->filter( $results, $excludes ); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
} |