Reputation: 59
I am using Autodesk Forge Viewer.
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". I only want to search for SG-100.
How can I do this? Help!
Upvotes: 0
Views: 1369
Reputation: 39
I agree with Augusto's suggestion that you'd need to limit the search scope to specific properties only to avoid partial matches. 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
'. 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. Pay attention, that the search
method belong to the viewer
object but the getBulkProperties
method belongs to the viewer.model
object.
Upvotes: 0
Reputation: 8604
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']);
Upvotes: 1