28 Star 66 Fork 17

Kenny小狼 / elasticsearch-js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause

ElasticSearch

前端ElasticSearch实现查询的工具类,例子见 demo.html

查询说明

  • 用户输入多添加时,多个查询条件用空格分割,但如果实际查询条件中带空格,请用双引号(""),括起来。
  • 查询条件中,支持"非"操作,例如 -广州, 意思是 不要包含广州 的内容。

例如:

中国 广州 -女 "hello world" -"one two"

查询条件是5个,其中 1,中国。2、广州。3、hello world 为必须包含的内容,但需要过滤掉包含 one two 的结果。

工具说明

  • ElasticSearch

ElasticSearch工具类

/**
* 返回构建的QueryBody实例查询体对象
*
* @param text 用户输入的文本
* @param types 可选,指定查询文档类型(type)
* @returns QueryBody 返回QueryBody实例。
*/
getQueryBody: function (text, types)
  • QueryBody

查询体对象

/**
* 设置查询范围
*
* @param prop 范围字段名
* @param gte 大于等于
* @param lte 小于等于
* @returns {QueryBody}
*/
setRange: function (prop, gte, lte)

/**
*
* 设置必须检索的条件
*
* @param prop 检索的字段名
* @param query 查询的字段
* @param isPhrase 是否词组匹配
* @param operator 逻辑符,and和or
* @returns {QueryBody}
*/
addMust: function (prop, query, isPhrase, operator)

/**
 *
 * 设置"不"必须检索的条件
 *
 * @param prop 检索的字段名
 * @param query 查询的字段
 * @param isPhrase 是否词组匹配
 * @param operator 逻辑符,and和or
 * @returns {QueryBody}
 */
addMustNot: function (prop, query, isPhrase, operator) {

/**
 *
 * 返回json对象
 *
 * @returns {*}
 */
toJSON: function ()

/**
 *
 * 设置检索的文档类型。
 *
 * @param types 数组
 * @returns {QueryBody}
 */
setTypes: function (types)

/**
 *
 * 设置检索的起始条目。
 *
 * @param index
 * @returns {QueryBody}
 */
setStartIndex: function (index)

/**
 *
 * 设置检索的分页大小。
 *
 * @param size
 * @returns {QueryBody}
 */
setPageSize: function (size)

/**
 *
 * 设置查询时,过滤的source属性。
 *
 * @param arr 数组
 * @returns {QueryBody}
 */
setExcludesProps: function (arr)

/**
 * 返回JSON的字符串
 *
 * @returns String
 */
toString: function ()
Copyright (c) 2017, Kenny小狼 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the {organization} nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

elasticsearch的前端工具类。不同于官方elasticsearch-js的地方是,重在搜索,尽可能低的学习成本。 展开 收起
JavaScript
BSD-3-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/kennylee/elasticsearch-js.git
git@gitee.com:kennylee/elasticsearch-js.git
kennylee
elasticsearch-js
elasticsearch-js
master

搜索帮助