1 | <?php |
||
32 | class WikidataQueryItemIdForQueryLookup implements ItemIdForQueryLookup { |
||
33 | |||
34 | /** |
||
35 | * @var SimpleQueryService |
||
36 | */ |
||
37 | private $queryService; |
||
38 | |||
39 | /** |
||
40 | * @param SimpleQueryService $queryService |
||
41 | */ |
||
42 | 15 | public function __construct( SimpleQueryService $queryService ) { |
|
45 | |||
46 | /** |
||
47 | * @see ItemIdForQueryLookup::getItemIdsForQuery |
||
48 | */ |
||
49 | 15 | public function getItemIdsForQuery( Description $queryDescription, QueryOptions $queryOptions = null ) { |
|
52 | |||
53 | 15 | private function buildQueryForDescription( Description $description, PropertyId $propertyId = null ) { |
|
54 | 15 | if( $description instanceof AnyValue ) { |
|
55 | 3 | return $this->buildQueryForAnyValue( $propertyId ); |
|
56 | 14 | } elseif( $description instanceof Conjunction ) { |
|
57 | 2 | return $this->buildQueryForConjunction( $description, $propertyId ); |
|
58 | 14 | } elseif( $description instanceof Disjunction ) { |
|
59 | 2 | return $this->buildQueryForDisjunction( $description, $propertyId ); |
|
60 | 14 | } elseif( $description instanceof SomeProperty ) { |
|
61 | 12 | return $this->buildQueryForSomeProperty( $description ); |
|
62 | 11 | } elseif( $description instanceof ValueDescription ) { |
|
63 | 10 | return $this->buildQueryForValueDescription( $description, $propertyId ); |
|
64 | } else { |
||
65 | 1 | throw new FeatureNotSupportedException( 'Unknown description type: ' . $description->getType() ); |
|
66 | } |
||
67 | } |
||
68 | |||
69 | 3 | private function buildQueryForAnyValue( PropertyId $propertyId = null ) { |
|
70 | 3 | if( $propertyId === null ) { |
|
71 | 1 | throw new FeatureNotSupportedException( 'Search for all items is not supported' ); |
|
72 | } |
||
73 | |||
74 | 2 | return new ClaimQuery( $propertyId ); |
|
75 | } |
||
76 | |||
77 | 2 | private function buildQueryForConjunction( Conjunction $conjunction, PropertyId $propertyId = null ) { |
|
78 | 2 | $parameters = []; |
|
79 | 2 | foreach( $conjunction->getDescriptions() as $description ) { |
|
80 | 2 | $parameters[] = $this->buildQueryForDescription( $description, $propertyId ); |
|
81 | 2 | } |
|
82 | 2 | return new AndQuery( $parameters ); |
|
83 | } |
||
84 | |||
85 | 2 | private function buildQueryForDisjunction( Disjunction $disjunction, PropertyId $propertyId = null ) { |
|
86 | 2 | $parameters = []; |
|
87 | 2 | foreach( $disjunction->getDescriptions() as $description ) { |
|
88 | 2 | $parameters[] = $this->buildQueryForDescription( $description, $propertyId ); |
|
89 | 2 | } |
|
90 | 2 | return new OrQuery( $parameters ); |
|
91 | } |
||
92 | |||
93 | 12 | private function buildQueryForSomeProperty( SomeProperty $someProperty ) { |
|
109 | |||
110 | 10 | private function buildQueryForValueDescription( ValueDescription $valueDescription, PropertyId $propertyId = null ) { |
|
111 | 10 | if( $propertyId === null ) { |
|
112 | 1 | throw new FeatureNotSupportedException( 'Search of value on any properties is not supported' ); |
|
113 | } |
||
133 | |||
134 | 5 | private function buildEntityIdValueForSearch( EntityIdValue $entityIdValue, PropertyId $propertyId ) { |
|
143 | } |
||
144 |