- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 fos_elastica 在 symfony2 项目中实现 elasticsearch。
一切正常(索引数据、更新等)
我目前正在寻找用户行为分析:我想获得用户搜索最多的 10 个或关键字,以便重新查询它。
例如:
如果 45% 的搜索是关于黄色气球的,45% 是关于红色气球的,我想在我的主页上推荐一些黄色或红色的气球
首先,我正在考虑创建一个 symfony2 实体来保存带有时间戳的用户搜索,然后计算最后 1000 次搜索以获得最著名的关键字。尽管它肯定会起作用,但这将是资源 killer 。
我想知道 elasticsearch 是否能够提供这些以及如何实现它。
我读过我可以创建一个索引来存储我的用户查询(这会很棒,因为我可以使用分面来非常轻松地计算它们),但我不知道如何在 Elasticsearch 中直接保存它来自 symfony2,没有专门的实体。
最佳答案
好吧,我终于明白了!
以下是不同的步骤:
1) 在 config.yml 中创建一个新索引,为您的关键字搜索提供特定的映射
in config.yml
indexes:
your_index:
types:
search:
mappings:
value: {type:string}
date : {type:date}
provider: acme\AppBundle\Service\SearchProvider
2) 在Service目录下新建类SearchProvider
in acme\Appbundle\Service\SearchProvider
<?php
namespace acme\AppBundle\Service;
use FOS\ElasticaBundle\Provider\ProviderInterface;
use Elastica\Type;
use Elastica\Document;
class SearchProvider implements ProviderInterface
{
protected $searchType;
private $search;
public function __construct(Type $searchType)
{
$this->searchType = $searchType;
}
// the function you will call from your service
public function add( $search )
{
$this->search = $search;
$this->populate();
}
/**
* Insert the repository objects in the type index
*
* @param \Closure $loggerClosure
* @param array $options
*/
public function populate(\Closure $loggerClosure = null, array $options = array())
{
if ($loggerClosure) {
$loggerClosure('Indexing users');
}
$date = time();
$document = new Document();
$document->setData(array('value' => $this->search, 'date' => $date ) );
$this->userType->addDocuments(array($document));
$this->userType->getIndex()->refresh();
}
}
3) 在你的 service.yml 中创建一个新的服务声明
services:
acme.search_provider:
class: acme\AppBundle\Service\SearchProvider
arguments:
- @fos_elastica.index.recetas.search
tags:
- { name: fos_elastica.provider, index: your_index, type: search }
4) 像这样调用您的服务来存储新搜索
$this->get("acme.search_provider")->add("kapoue");
kapoue 将被添加到搜索中。
5) 获取所有搜索关键词并聚合排序
$es = $this->get('fos_elastica.index.acme.search');
$query = new \Elastica\Query();
$aggregation = new \Elastica\Aggregation\Terms("top_hits");
$aggregation->setField('value');
$aggregation->setSize( 3 );
$query->addAggregation($aggregation);
$result = $es->search($query);
$mostResearched = $result->getAggregation("top_hits");
print_r ( $mostResearched ); die();
关于symfony - Elasticsearch : How to get most researched terms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28066283/
我正在尝试使用Apple的ResearchKit进行调查,但是找不到如何更改预定义按钮的颜色。它们是蓝色的,但我想使它们具有不同的颜色。这个怎么做? 最佳答案 使用UIView的外观代理设置色调颜色应
我尝试创建一个新的研究人员,但我只是陷入了困境,并且没有出现任何错误。我是使用 sequelize 的新手,我需要很多帮助来解决这个问题,我在 git 中的完整代码: https://github.c
我正在使用 fos_elastica 在 symfony2 项目中实现 elasticsearch。 一切正常(索引数据、更新等) 我目前正在寻找用户行为分析:我想获得用户搜索最多的 10 个或关键字
大家好,我是 Swift 的新手,我尝试使用研究工具包应用程序构建饼图。 我引用这个 link 写了一些代码 当运行我的代码时,它显示错误“Type 'ViewController' does not
我目前正在从事学术目的的自然语言处理工作,我想获取 Microsoft Research Sentence Completion Challenge 数据集。 不幸的是,它似乎不再可用 on Micr
如何在 colab.research.google 上安装 rpy2?我尝试了以下命令: pip install rpy2 import rpy2 但它不起作用。这是得到的错误: Collecting
运行“https://github.com/tensorflow/federated/blob/master/tensorflow_federated/python/research/gans/exp
我是 python selenium 的菜鸟。我必须从 Research Gate 中某个机构的成员页面导航所有成员,这意味着我必须单击第一个成员才能转到他们的个人资料页面,然后返回到成员页面以单击下
嗨! 在哪里可以找到 Microsoft.Research.Kinect.dll?我已经安装了 Kinect SDK 1.5 和它的工具包,但我没有找到 dll。我不知道。如果你知道请与我分享 最佳答
我知道 apple 尚未发布用于开发的研究套件。 https://developer.apple.com/researchkit/说会在下个月发布。 但是http://fortune.com/2015
所以我想使用 python-occ 库。它需要 conda-forge 来构建。我尝试将其安装在 basic notebook 中 !wget -c https://repo.continuum.io
我将其提交到 Stack Overflow,而不是作为 Tensorflow 问题,因为根据提交到 Tensorflow 的问题(例如 here ),人们能够解决我遇到的问题。我以 Tensorflo
我正在尝试抓取列出法国众贷金融科技网站的研究成果:https://www.orias.fr/web/guest/search 手动执行此操作,我在单选按钮中选择 (IFP),然后它为我提供 13 个结
我使用的是 Point Grey Research BumbleBee 2 相机及其 SDK。我有这个循环来连续抓取帧,但它不起作用。它捕获了第一帧,但 triclopsGetImage() 似乎没有
我知道,我知道,你会告诉我检查我的路径和注册表。我有,相信我。 我的情况——我们有两个机器运行相同的代码和相同的 web.config 文件。以下是两者的规范。 IIS 7.0,配置为在午夜重置应用程
我一直在努力寻找一些资源,以便为 Android 平台(API 级别 17)上的可访问性研究项目构建键盘记录器 Android 应用程序。 应用程序的界面将是一个简单的“EditText” 字段,用户
我知道如何在笔记本中运行脚本(例如 this post )。现在的问题是如何在 python 中读取 shell 脚本的结果?比如我们有一个echo "hi"命令,或者我们调用一个shell脚本,我们
我想在 colab.research.google.com 中使用 Chrome 的 Selenium Webdriver 进行快速处理。我能够使用 !pip install selenium 安装
我想调用 ESHA Research 营养 REST API。我似乎无法弄清楚如何使用 ESHA REST API 调用多种营养素。到目前为止,我正在调用以下内容,并且只能检索卡路里、蛋白质或其他
错误: ... Caused by: java.lang.ExceptionInInitializerError ... Caused by: java.lang.ClassCastException
我是一名优秀的程序员,十分优秀!