mmanos / laravel-search

A search package for Laravel 5.
MIT License
352 stars 59 forks source link

Can't get select field of records, just show me ID array #38

Open thanhmabo opened 9 years ago

thanhmabo commented 9 years ago

Hello @mmanos I am using Zend search lunce with laravel-search , i tested on my local. "laravel/framework": "5.1.*" my config

return array(
    'default' => 'zend',
    'default_index' => 'default',
    'connections' => array(
        'zend' => array(
            'driver' => 'zend',
            'path'   => storage_path().'/search',
        ),
        'elasticsearch' => array(
            'driver' => 'elasticsearch',
            'config' => array(
                'hosts' => array('localhost:9200'),
            ),
        ),

        'algolia' => array(
            'driver' => 'algolia',
            'config' => array(
                'application_id' => '',
                'admin_api_key'  => '',
            ),
        ),
    ),
);

I have a data with 500 records and create Index with function getArticle

public function getArticle(){
        $items = Article::skip(0)->take(500)->get();
        foreach($items as $key=>$item){
            \Search::insert($item->id, array(
                'title'     => $item->title,
                'introtext' => $item->introtext,
                'fulltext'  => $item->fulltext,
                'status'    => $item->status,
            ));
        }
    }

I create a function to search, but result just show me a array IDs

    public function getSearch($kw){
        $items = \Search::search(array('title'),$kw,array('fuzzy'=>true))->limit(15,0)->get();
        var_dump($items);
    }

result

array (size=1)
  0 => 
    array (size=2)
      'id' => string '411' (length=3)
      '_score' => float 1

I change my function to select field

public function getSearch($kw){
        $items = \Search::select('id', 'title')->search(array('title'),$kw,array('fuzzy'=>true))->limit(15,0)->get();
        var_dump($items);
    }

result

array (size=1)
  0 => 
    array (size=1)
      'id' => string '241' (length=3)

what happen, was i doing something wrong .

bakerstreetsystems commented 9 years ago

I have the same issue.

dmyers commented 9 years ago

I believe this was fixed in the Laravel 4.x branch I just need to merge them into the 5.x branch and test a bit.

thanhmabo commented 9 years ago

Thanks @dmyers

stu177 commented 8 years ago

Having the same issue with the latest version, any ideas?

bekatama commented 8 years ago

Yes me too. Having the same issue, just show me ID ARRAY