bsdd search to check whether query is long enough

It's an API requirement and using shorter queries was giving confusing results.
https://github.com/buildingSMART/bSDD/blob/master/Documentation/bSDD%20OpenAPI.yaml
This commit is contained in:
Andrej730
2024-09-18 16:02:15 +05:00
parent 8f7949808a
commit eb823a5ecd
5 changed files with 22 additions and 6 deletions
@@ -50,6 +50,14 @@ class SearchBSDDClass(bpy.types.Operator):
bl_description = "Search for bSDD classes by the provided keyword"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
# Requirement by buildingSMART bSDD api.
if len(context.scene.BIMBSDDProperties.keyword) < 3:
cls.poll_message_set("Search query has to be at least 3 characters long.")
return False
return True
def execute(self, context):
keyword = context.scene.BIMBSDDProperties.keyword
classes_found = core.search_class(keyword, bsdd.Client(), tool.Bsdd)
+1 -1
View File
@@ -60,7 +60,7 @@ class BIMBSDDProperties(PropertyGroup):
active_domain_index: IntProperty(name="Active Domain Index")
classifications: CollectionProperty(name="Classifications", type=BSDDClassification)
active_classification_index: IntProperty(name="Active Classification Index")
keyword: StringProperty(name="Keyword")
keyword: StringProperty(name="Keyword", description="Query for bsdd classes search, case and accent insensitive")
should_filter_ifc_class: BoolProperty(
name="Filter Active IFC Class",
description="Whether to search only for bSDD classes that match active object's IFC class",
+1 -1
View File
@@ -47,7 +47,7 @@ def load_bsdd(client: bsdd.Client, bsdd: tool.Bsdd) -> None:
def search_class(keyword: str, client: bsdd.Client, bsdd: tool.Bsdd) -> int:
bsdd.clear_classes()
related_entities = bsdd.get_related_ifc_entities(keyword)
related_entities = bsdd.get_related_ifc_entities()
active_dictionary_uri = bsdd.get_active_dictionary_uri()
classes = bsdd.search_class(client, keyword, [active_dictionary_uri], related_entities)
bsdd.create_classes(classes)
+1 -3
View File
@@ -121,11 +121,9 @@ class Bsdd(bonsai.core.tool.Bsdd):
return psets
@classmethod
def get_related_ifc_entities(cls, keyword: str) -> list[str]:
def get_related_ifc_entities(cls) -> list[str]:
active_object = bpy.context.active_object
related_ifc_entities = []
if len(keyword) < 3:
return []
if cls.should_filter_ifc_class() and active_object:
element = tool.Ifc.get_entity(active_object)
if element:
+11 -1
View File
@@ -492,6 +492,10 @@ class Client:
# deprecated
def ClassificationSearchOpen(self, SearchText, version="v1", DomainNamespaceUris=None, RelatedIfcEntities=None):
print(f"function 'Client.ClassificationSearchOpen' is deprecated, use 'Client.search_class' instead")
if len(SearchText) < 3:
raise ValueError("Search text must be at least 3 characters long.")
if DomainNamespaceUris is None:
DomainNamespaceUris = []
if RelatedIfcEntities is None:
@@ -686,6 +690,10 @@ class Client:
So if result consists of 10 classes and 5 properties, TotalCount will be 15.
Classes will be listed first, so if you then use Offset=10 and Limit=5, you will get the 5 properties.
"""
if len(search_text) < 2:
raise ValueError("Search text must be at least 2 characters long.")
if dictionary_uris is None:
dictionary_uris = []
endpoint = f"TextSearch/v{version}"
@@ -697,7 +705,6 @@ class Client:
"limit": limit,
}
return self.get(endpoint, params)
pass
def search_in_dictionary(
self,
@@ -739,6 +746,9 @@ class Client:
this API replaces ClassificationSearch
"""
if len(search_text) < 3:
raise ValueError("Search text must be at least 3 characters long.")
if related_ifc_entities is None:
related_ifc_entities = []
if dictionary_uris is None: