我正在使用Laravel、ElasticSearch和MongoDB构建一个web应用程序。为此,我使用https://github.com/jenssegers/laravel-mongodb连接Laravel和MongoDB (它工作得很好),使用https://github.com/elasticquent/Elasticquent连接到Elasticsearch (我对它有问题)。
我的模型是这样的:
namespace App;
use Moloquent;
use Elasticquent\ElasticquentTrait;
class Article extends Moloquent
{
use ElasticquentTrait;
protected $collection = 'Articles';
}我的控制器搜索函数如下所示:
public function search()
{
$texte = $_GET['texte'];
$articles = Article::where('Title', 'regexp', "/$texte/")->get();
//$articles = Article::search('bu');
//dd($articles);
return view('pages.articles', compact('articles'));
}当使用来自文章模型的where函数时,我得到了这样的结果,这是3个结果
ElasticquentCollection {#134 ▼
#items: array:3 [▼
0 => Article {#142 ▶}
1 => Article {#143 ▶}
2 => Article {#144 ▶}
]
}当使用搜索功能时,我得到类似这样的结果,没有结果
ElasticquentResultCollection {#156 ▼
#took: 1
#timed_out: false
#shards: array:3 [▶]
#hits: array:3 [▶]
#aggregations: []
#instance: Article {#161 ▶}
#items: []
}有没有人必须处理同样类型的架构,并且可以帮助我解决这个问题?
谢谢你的帮助!
发布于 2016-02-25 00:17:23
变化
$articles = Article::search('bu');至
$articles = Article::search('bu')->get();您不是在提取集合。您必须使用get()或first()来收集搜索到的项目。
https://stackoverflow.com/questions/35607231
复制相似问题