自动完成/预输入angularjs上elasticsearch引导 [英] autocomplete/typeahead angularjs bootstrap on elasticsearch

查看:185
本文介绍了自动完成/预输入angularjs上elasticsearch引导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个有效的解决方案来获得自动完成/预输入与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']);
    sea​​rchModules.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);
         }
         返回关键字;
      });
    }
    });

    希望它能帮助

    这篇关于自动完成/预输入angularjs上elasticsearch引导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆