简体   繁体   English

Autodesk Forge 查看器,搜索

[英]Autodesk Forge Viewer, Search

I am using Autodesk Forge Viewer.我正在使用 Autodesk Forge 查看器。

viewer.search('"' + keyword +'"', function(e)
{
    viewer.select(e);
    viewer.fitToView(e);
}

I am searching like this.我是这样搜索的。 The problem is that it searches for both "SG-100" and "SSG-100".问题是它同时搜索“SG-100”和“SSG-100”。 I only want to search for SG-100.我只想搜索 SG-100。

How can I do this?我怎样才能做到这一点? Help!帮助!

My suggestion would be to do a second filter inside the search:我的建议是在搜索中做第二个过滤器:

viewer.search(keyword, (dbIds) => {
   // success
   viewer.getBulkProperties(dbIds, ['AttributeName'], (elements) => {
      let dbIdsToSelect = [];
      for(var i=0; i<elements.length; i++){
         if (elements[i].properties[0].displayValue===keyword)
            dbIdsToSelect.push(elements[i].dbId;
      }

      viewer.select(dbIdsToSelect);
      viewer.fitToView(dbIdsToSelect);
   }
}, (e) => {
   // error, handle here...
}, ['AttributeName']);

I agree with Augusto's suggestion that you'd need to limit the search scope to specific properties only to avoid partial matches.我同意 Augusto 的建议,即您需要将搜索 scope 限制为特定属性,以避免部分匹配。 According to the search function description it's supposed to do just that if you provide the list of property names in the 4th argument that is called ' attributeNames '.根据search function 描述,如果您在名为“ attributeNames ”的第四个参数中提供属性名称列表,则应该这样做。 Unfortunately, from my experience, that does not work, so you need a second level filtering by using a getBulkProperties function that will reduce the list of dbIds from the search to only those that have specific properties defined.不幸的是,根据我的经验,这不起作用,因此您需要使用getBulkProperties function 进行二级过滤,这会将搜索中的 dbId 列表减少到仅定义了特定属性的那些。 Pay attention, that the search method belong to the viewer object but the getBulkProperties method belongs to the viewer.model object.请注意, search方法属于viewer object,但getBulkProperties方法属于查看器viewer.model object。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM