资讯专栏INFORMATION COLUMN

修改forge search方法,加入完全匹配标记,解决搜索是模糊搜索问题

sumory / 401人阅读

摘要:行修改加入关键字,为时为完全匹配,为时为包含行修改加入关键字,为时为完全匹配,为时为包含行修改加入关键字,为时为完全匹配,为时为包含行修改加入关键字,为时为完全匹配,为时为包含添加行修改加入关键字,为时为完全匹配,为时为

viewer3d.js
15194行

/**
 * 修改2019-8-6 加入perfectMatch关键字,
 * perfectMatch为true时为完全匹配,为false时为包含
 * 
 */
Model.prototype.search = function (text, onSuccessCallback, onErrorCallback, attributeNames,perfectMatch)
{
  var pdb = this.getPropertyDb();

  if (!pdb) {
    onErrorCallback && onErrorCallback();
    return;
  }

  pdb.searchProperties(text, attributeNames, onSuccessCallback, onErrorCallback,perfectMatch);
};

19173行

/**
 * 修改2019-8-6 加入perfectMatch关键字,
 * perfectMatch为true时为完全匹配,为false时为包含
 *
 */

Viewer3D.prototype.search = function (text, onSuccessCallback, onErrorCallback, attributeNames,perfectMatch)
{
  this.searchText = text;

  if (this.model) {
    this.model.search(text, onSuccessCallback, onErrorCallback, attributeNames,perfectMatch);
  } else
  {
    if (onErrorCallback)
    onErrorCallback(_file_loaders_net_ErrorCodes__WEBPACK_IMPORTED_MODULE_6__["ErrorCodes"].BAD_DATA, "Search failed since model does not exist");
  }
};

38881行

/**
 * 修改2019-8-6 加入perfectMatch关键字,
 * perfectMatch为true时为完全匹配,为false时为包含
 *
 */
PropDbLoader.prototype.searchProperties = function (searchText, attributeNames, onSuccess, onError,perfectMatch) {

  this.asyncPropertyOperation(
  {
    "operation": WORKER_SEARCH_PROPERTIES,
    "searchText": searchText,
    "attributeNames": attributeNames,
      "perfectMatch":perfectMatch
  },

  onSuccess, onError);

};

lmvworker.js
35941行

/**
 * 修改2019-8-6 加入perfectMatch关键字,
 * perfectMatch为true时为完全匹配,为false时为包含
 * @param loadContext
 */

function doPropertySearch(loadContext) {

  var _this = loadContext.worker;
  // 添加
  var perfectMatch = loadContext.perfectMatch;
  var cacheEntry = _this.pdbCache && _this.pdbCache[loadContext.dbPath];

  if (cacheEntry && cacheEntry.pdb) {
    var searchText = loadContext.searchText;
    var result = cacheEntry.pdb.bruteForceSearch(searchText, loadContext.attributeNames,perfectMatch);
    _this.postMessage({ cbId: loadContext.cbId, result: result });
  }

}

22754行

  /**
      * Searches the property database for a string.
      * 修改2019-8-6 加入perfectMatch关键字,
      * perfectMatch为true时为完全匹配,为false时为包含
      *
      * 
      * @returns Array of ids.
      */
  this.bruteForceSearch = function (searchText, attributeNames,perfectMatch) {

    var searchList = this.getSearchTerms(searchText);

    if (searchList.length === 0)
    return [];

    //For each search word, find matching IDs
    var results = [];

    for (var k = 0; k < searchList.length; k++) {
      var result = [];

      //Find all values that match the search text
      var matching_vals = [];
      for (var i = 0, iEnd = _valuesOffsets.length; i < iEnd; i++) {
        var val = this.getValueAt(i);
        if (val === null)
        continue;

        // 原方法
          // if (val.toString().toLowerCase().indexOf(searchList[k]) !== -1){
          //
          //     matching_vals.push(i);
          // }

        //此处修改
        if(perfectMatch){
            if (val.toString().toLowerCase() === searchList[k] ){

                matching_vals.push(i);
            }
        }else{
            if (val.toString().toLowerCase().indexOf(searchList[k]) !== -1){

                matching_vals.push(i);
            }
        }


      }

      if (matching_vals.length === 0) {
        results.push(result);
        continue;
      }

      // values should be sorted at this point, but it doesn"t hurt making sure they are.
      matching_vals.sort(function (a, b) {
        return a - b;
      });

      this.enumObjects(function (id) {

        _this.enumObjectProperties(id, function (attrId, valId) {

          // skip hidden attributes
          var isHidden = _this.attributeHidden(attrId);
          if (isHidden) {
            return;
          }

          var iFound = Object(_common_SearchUtils__WEBPACK_IMPORTED_MODULE_1__["binarySearch"])(matching_vals, valId);

          if (iFound !== -1) {

            //Check attribute name in case a restriction is passed in
            if (attributeNames && attributeNames.length && attributeNames.indexOf(_attrs[attrId][0]) === -1)
            return;

            result.push(id);
            return true;
          }
        });

      });

      results.push(result);
    }

    if (results.length === 1) {
      return results[0];
    }

    //If each search term resulted in hits, compute the intersection of the sets
    var map = {};
    var hits = results[0];
    for (var i = 0; i < hits.length; i++) {
      map[hits[i]] = 1;}


    for (var j = 1; j < results.length; j++) {
      hits = results[j];
      var mapint = {};

      for (var i = 0; i < hits.length; i++) {
        if (map[hits[i]] === 1)
        mapint[hits[i]] = 1;
      }

      map = mapint;
    }

    var result = [];
    for (var k in map) {
      result.push(parseInt(k));
    }

    return result;
  };

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/106456.html

相关文章

  • 前端做模糊搜索

    摘要:到目前为止我们只实现了搜索功能,按更优的体验来讲,在搜索结果中,要优先把相连匹配的放在首位,如关键字,要把结果放到前面。 我们先看一下效果图:showImg(https://segmentfault.com/img/remote/1460000015486183?w=199&h=107); 这是搜索关键字cfg时,会自动匹配到config方法 同样,我们再看另一个例子 showImg(...

    shadowbook 评论0 收藏0
  • Lucene介绍与应用

    摘要:创建用来对查询语句进行词法分析和语言处理。调用对查询语法树进行搜索,得到结果。代码中用到了分词器,是第三方实现的分词器,继承自的类,针对中文文本进行处理的分词器。 Lucene介绍与应用 GitHub地址:https://github.com/yizuoliang... 一、全文检索介绍 1.数据结构 结构化数据: 指具有固定格式 或限定长度的数据; 例如:数据库中的数据、元数据…...

    genedna 评论0 收藏0
  • 深度学习在美团点评的应用

    摘要:基于深度学习的语义匹配语义匹配技术,在信息检索搜索引擎中有着重要的地位,在结果召回精准排序等环节发挥着重要作用。在美团点评业务中主要起着两方面作用。 写在前面美团点评这两年在深度学习方面进行了一些探索,其中在自然语言处理领域,我们将深度学习技术应用于文本分析、语义匹配、搜索引擎的排序模型等;在计算机视觉领域,我们将其应用于文字识别、目标检测、图像分类、图像质量排序等。下面我们就以语义匹配、图...

    DirtyMind 评论0 收藏0
  • Lucene就这么容易

    摘要:就其本身而言,是当前以及最近几年最受欢迎的免费信息检索程序库。这样完全和数据库进行了隔离。当一个文档出现在了搜索结果中,这就意味着该文档与用户给定的查询语句是相匹配的。 showImg(https://segmentfault.com/img/bVbuifx?w=258&h=258);公众号阅读https://mp.weixin.qq.com/s/M3... Lucene [TOC] ...

    894974231 评论0 收藏0
  • Elastic Search快速上手(4):细节补充

    摘要:前缀部分必须完全匹配。搜索建议搜索建议功能,需要配合程序,在向中存入文档时,就需要通过分词等方式,指定搜索建议字段的内容。注意,高亮的结果在返回时单独存放,并不是将数据做了改变。的官方文档是最好的参考资料,介绍很全面。 模糊搜索 可以进行模糊搜索: GET job/type1/_search { query:{ fuzzy:{ title:{ v...

    JohnLui 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<