我一直在寻找一个有效的解决方案来获得自动完成/预输入与angularjs&安培;引导elasticsearch服务器上
I was looking for a working solution to get autocomplete/typeahead with angularjs&bootstrap on elasticsearch server.
推荐答案
这是一个可行的解决方案,而不是一个问题,但我想分享它希望这将有助于:
This is a working solution, not a question, but i want to share it hope it will help :
在html code调用自动完成功能:
the html code to call the autocomplete function :
<input required type="text"
popover-trigger="focus"
placeholder="recherche globale"
class="form-control"
ng-model="simplequeryInput"
ng-model-onblur focus-on="focusMe"
ng-click="searchSimple=true" ng-keyup="$event.keyCode == 13 ? submitSimple() : null"
typeahead="item for item in autocomplete($viewValue) | limitTo:15 "
typeahead-on-select="simplequeryInput=$model"
/>
提供elasticsearch(V2.4.0)脚本可她: http://pastebin.com/WhPSL54h
我elasticsearch服务
my elasticsearch service
interfaceApp.service('elasticQuery',函数($ rootScope,esFactory){返回esFactory({主持人:$ rootScope.elastic_host}); //'本地主机:9200'});
angularjs code quering elasticsearch:
angularjs code quering elasticsearch :
使用严格的;变种searchModules = angular.module('searchModules',['ngRoute','ngDialog']);searchModules.controller('searchCtrl',函数(ngDialog,$范围,$ HTTP,$ rootScope,elasticQuery){...$ scope.autocomplete =功能(VAL){ 变种关键字= []; keywords.push(VAL); //这个回报是非常重要的 返回elasticQuery.search({ 索引:YOUR_INDEX_NAME', 尺寸:15, 身体: { 田:T_FAMILY,T_GENUS,T_SCIENTIFICNAME],//你需要的字段 查询:{ BOOL:{ 必须:[{ QUERY_STRING:{ 查询:T_FAMILY:+ VAL //我想唯一的来源在哪里FAMILY == VAL } }] } } } })。然后(功能(响应){ 对(在response.hits.hits变种I){ VAR栏=(response.hits.hits [I])领域。 VAR tmpObject =域[T_FAMILY] ++田[T_GENUS] +(+田[T_SCIENTIFICNAME] +); keywords.push(tmpObject); } 返回关键字; });}});
希望它能帮助
相关推荐
最新文章