src/forms/HasOneAutocompleteField.php
protected function getResults($query)
    {
         $searchFields = ($this->getSearchFields() ?: singleton($this->sourceObject)->stat('searchable_fields'));

        if(!$searchFields) {
            throw new Exception(
                sprintf('HasOneAutocompleteField: No searchable fields could be found for class "%s"',
                $this->sourceObject));
        }

        $params = [];
        $sort = [];
        
        foreach($searchFields as $searchField) {
            $name = (strpos($searchField, ':') !== FALSE) ? $searchField : "$searchField:PartialMatch:nocase";
            $params[$name] = $query;
            $sort[$searchField] = "ASC";
        }

        $results = DataList::create($this->sourceObject)
            ->filterAny($params)
            ->sort($sort)
            ->limit($this->getResultsLimit());

        return $results;
    }
protected function getResults($query)
    {
         $searchFields = ($this->getSearchFields() ?: singleton($this->sourceObject)->stat('searchable_fields'));

        if(!$searchFields) {
            throw new Exception(
                sprintf('HasOneAutocompleteField: No searchable fields could be found for class "%s"',
                $this->sourceObject));
        }

        $params = [];
        $sort = [];
        
        foreach($searchFields as $searchField) {
            $name = (strpos($searchField, ':') !== FALSE) ? $searchField : "$searchField:PartialMatch:nocase";
            $params[$name] = $query;
            $sort[$searchField] = "ASC";
        }

        $results = DataList::create($this->sourceObject)
            ->filterAny($params)
            ->sort($sort)
            ->limit($this->getResultsLimit());

        return $results;
    }
protected function getResults ( $ query ) { $ searchFields = ( $ this -> getSearchFields ( ) ? : singleton ( $ this -> sourceObject ) -> stat ( 'searchable_fields' ) ) ; if ( ! $ searchFields ) { throw new Exception ( sprintf ( 'HasOneAutocompleteField: No searchable fields could be found for class "%s"' , $ this -> sourceObject ) ) ; } $ params = [ ] ; $ sort = [ ] ; foreach ( $ searchFields as $ searchField ) { $ name = ( strpos ( $ searchField , ':' ) !== FALSE ) ? $ searchField : "$searchField:PartialMatch:nocase" ; $ params [ $ name ] = $ query ; $ sort [ $ searchField ] = "ASC" ; } $ results = DataList :: create ( $ this -> sourceObject ) -> filterAny ( $ params ) -> sort ( $ sort ) -> limit ( $ this -> getResultsLimit ( ) ) ; return $ results ; }
Takes the search term and returns a DataList
@param  string $query
@return DataList
Takes the search term and returns a DataList