public function search()
    {
        $params = $this->getRequestParameter('params');
        $query = $params['query'];
        $class = $this->getClass($params['rootNode']);

        $rows = $this->hasRequestParameter('rows') ? (int)$this->getRequestParameter('rows') : null;
        $page = $this->hasRequestParameter('page') ? (int)$this->getRequestParameter('page') : 1;
        $startRow = is_null($rows) ? 0 : $rows * ($page - 1);

        try {
            $results = [];

            // if it is an URI
            if (strpos($query, LOCAL_NAMESPACE) === 0) {
                $resource = $this->getResource($query);
                if ($resource->exists() && $resource->isInstanceOf($class)) {
                    $results = new ResultSet([$resource->getUri()], 1);
                }
            }

            //  if there is no results based on considering the query as URI
            if (empty($results)) {
                $results = $this->getServiceLocator()->get(Search::SERVICE_ID)->query($query, $class->getUri(), $startRow, $rows);
            }

            $totalPages = is_null($rows) ? 1 : ceil( $results->getTotalCount() / $rows );

            $response = new StdClass();
            if(count($results) > 0 ){

                foreach($results as $uri) {
                    $instance = $this->getResource($uri);
                    $instanceProperties = array(
                        'id' => $instance->getUri(),
                        OntologyRdfs::RDFS_LABEL => $instance->getLabel()
                    );

                    $response->data[] = $instanceProperties;
                }
            }
    		$response->success = true;
            $response->page = empty($response->data) ? 0 : $page;
    		$response->total = $totalPages;
    		$response->records = count($results);

    		$this->returnJson($response, 200);
        } catch (SyntaxException $e) {
            $this->returnJson(array(
                'success' => false,
                'msg' => $e->getUserMessage()
            ));
        }
    }
public function search()
    {
        $params = $this->getRequestParameter('params');
        $query = $params['query'];
        $class = $this->getClass($params['rootNode']);

        $rows = $this->hasRequestParameter('rows') ? (int)$this->getRequestParameter('rows') : null;
        $page = $this->hasRequestParameter('page') ? (int)$this->getRequestParameter('page') : 1;
        $startRow = is_null($rows) ? 0 : $rows * ($page - 1);

        try {
            $results = [];

            // if it is an URI
            if (strpos($query, LOCAL_NAMESPACE) === 0) {
                $resource = $this->getResource($query);
                if ($resource->exists() && $resource->isInstanceOf($class)) {
                    $results = new ResultSet([$resource->getUri()], 1);
                }
            }

            //  if there is no results based on considering the query as URI
            if (empty($results)) {
                $results = $this->getServiceLocator()->get(Search::SERVICE_ID)->query($query, $class->getUri(), $startRow, $rows);
            }

            $totalPages = is_null($rows) ? 1 : ceil( $results->getTotalCount() / $rows );

            $response = new StdClass();
            if(count($results) > 0 ){

                foreach($results as $uri) {
                    $instance = $this->getResource($uri);
                    $instanceProperties = array(
                        'id' => $instance->getUri(),
                        OntologyRdfs::RDFS_LABEL => $instance->getLabel()
                    );

                    $response->data[] = $instanceProperties;
                }
            }
    		$response->success = true;
            $response->page = empty($response->data) ? 0 : $page;
    		$response->total = $totalPages;
    		$response->records = count($results);

    		$this->returnJson($response, 200);
        } catch (SyntaxException $e) {
            $this->returnJson(array(
                'success' => false,
                'msg' => $e->getUserMessage()
            ));
        }
    }
public function search ( ) { $ params = $ this -> getRequestParameter ( 'params' ) ; $ query = $ params [ 'query' ] ; $ class = $ this -> getClass ( $ params [ 'rootNode' ] ) ; $ rows = $ this -> hasRequestParameter ( 'rows' ) ? ( int ) $ this -> getRequestParameter ( 'rows' ) : null ; $ page = $ this -> hasRequestParameter ( 'page' ) ? ( int ) $ this -> getRequestParameter ( 'page' ) : 1 ; $ startRow = is_null ( $ rows ) ? 0 : $ rows * ( $ page - 1 ) ; try { $ results = [ ] ; // if it is an URI if ( strpos ( $ query , LOCAL_NAMESPACE ) === 0 ) { $ resource = $ this -> getResource ( $ query ) ; if ( $ resource -> exists ( ) && $ resource -> isInstanceOf ( $ class ) ) { $ results = new ResultSet ( [ $ resource -> getUri ( ) ] , 1 ) ; } } //  if there is no results based on considering the query as URI if ( empty ( $ results ) ) { $ results = $ this -> getServiceLocator ( ) -> get ( Search :: SERVICE_ID ) -> query ( $ query , $ class -> getUri ( ) , $ startRow , $ rows ) ; } $ totalPages = is_null ( $ rows ) ? 1 : ceil ( $ results -> getTotalCount ( ) / $ rows ) ; $ response = new StdClass ( ) ; if ( count ( $ results ) > 0 ) { foreach ( $ results as $ uri ) { $ instance = $ this -> getResource ( $ uri ) ; $ instanceProperties = array ( 'id' => $ instance -> getUri ( ) , OntologyRdfs :: RDFS_LABEL => $ instance -> getLabel ( ) ) ; $ response -> data [ ] = $ instanceProperties ; } } $ response -> success = true ; $ response -> page = empty ( $ response -> data ) ? 0 : $ page ; $ response -> total = $ totalPages ; $ response -> records = count ( $ results ) ; $ this -> returnJson ( $ response , 200 ) ; } catch ( SyntaxException $ e ) { $ this -> returnJson ( array ( 'success' => false , 'msg' => $ e -> getUserMessage ( ) ) ) ; } }
Search results
The search is paginated and initiated by the datatable component.
Search results The search is paginated and initiated by the datatable component .