public function searchBy($property, $value = null, $lang = 'en', $limit = 10) 
    {
        if(!is_pid($property)) {
            throw new Exception("First argument in searchBy() must be a valid Wikidata property ID (e.g.: P646).", 1);
        }

        if(!$value) {
            throw new Exception("Second argument in searchBy() must be a string or a valid Wikidata entity ID (e.g.: Q646).", 1);
        }

        $subject = is_qid($value) ? 'wd:'.$value : '"'.$value.'"';

        $query = '
            SELECT ?item ?itemLabel ?itemAltLabel ?itemDescription WHERE {
                ?item wdt:'.$property.' '.$subject.'.
                SERVICE wikibase:label {
                    bd:serviceParam wikibase:language "'. $lang .'".
                }
            } LIMIT '.$limit.'
        ';

        $client = new SparqlClient();

        $data = $client->execute( $query ); 

        $collection = collect($data);

        $output = $collection->map(function($item) use ($lang) {
            return new SearchResult($item, $lang, 'sparql');
        });

        return $output;
    }
public function searchBy($property, $value = null, $lang = 'en', $limit = 10) 
    {
        if(!is_pid($property)) {
            throw new Exception("First argument in searchBy() must be a valid Wikidata property ID (e.g.: P646).", 1);
        }

        if(!$value) {
            throw new Exception("Second argument in searchBy() must be a string or a valid Wikidata entity ID (e.g.: Q646).", 1);
        }

        $subject = is_qid($value) ? 'wd:'.$value : '"'.$value.'"';

        $query = '
            SELECT ?item ?itemLabel ?itemAltLabel ?itemDescription WHERE {
                ?item wdt:'.$property.' '.$subject.'.
                SERVICE wikibase:label {
                    bd:serviceParam wikibase:language "'. $lang .'".
                }
            } LIMIT '.$limit.'
        ';

        $client = new SparqlClient();

        $data = $client->execute( $query ); 

        $collection = collect($data);

        $output = $collection->map(function($item) use ($lang) {
            return new SearchResult($item, $lang, 'sparql');
        });

        return $output;
    }
public function searchBy ( $ property , $ value = null , $ lang = 'en' , $ limit = 10 ) { if ( ! is_pid ( $ property ) ) { throw new Exception ( "First argument in searchBy() must be a valid Wikidata property ID (e.g.: P646)." , 1 ) ; } if ( ! $ value ) { throw new Exception ( "Second argument in searchBy() must be a string or a valid Wikidata entity ID (e.g.: Q646)." , 1 ) ; } $ subject = is_qid ( $ value ) ? 'wd:' . $ value : '"' . $ value . '"' ; $ query = '
            SELECT ?item ?itemLabel ?itemAltLabel ?itemDescription WHERE {
                ?item wdt:' . $ property . ' ' . $ subject . '.
                SERVICE wikibase:label {
                    bd:serviceParam wikibase:language "' . $ lang . '".
                }
            } LIMIT ' . $ limit . '
        ' ; $ client = new SparqlClient ( ) ; $ data = $ client -> execute ( $ query ) ; $ collection = collect ( $ data ) ; $ output = $ collection -> map ( function ( $ item ) use ( $ lang ) { return new SearchResult ( $ item , $ lang , 'sparql' ) ; } ) ; return $ output ; }
Search entities by property ID and it value

@param string $property Wikidata ID of property (e.g.: P646)
@param string $value String value of property or Wikidata entity ID (e.g.: Q11696)
@param string $lang Language (default: en)
@param string $limit Max count of returning items (default: 10)

@return \Illuminate\Support\Collection Return collection of \Wikidata\SearchResult
Search entities by property ID and it value