Jump to content

Search Widget not able to set results


Nitish

Recommended Posts

I am trying to create a SeeQ addon to search by a property which the existing Search does not allow to search by. 

This code displays the search widget. 

item_selector = spy.widgets.SeeqItemSelect(
    '<H2>Tag Search by UID</H2>',
    show_fields = ['Name'],
    item_type = 'Signal',
    results_box_rows = 15, 
    max_displayed_results = 20
)

display(item_selector)

When I enter a search term, and click the Search button, I am able to run this code to search for the results. 

# Actions 
def searchTagByUid(uid):
    results = spy.search({
            'Data ID': uid
        }, 
        all_properties = True
    )
    

if "Name" in item_selector.search_terms:
    results = searchTagByUid(item_selector.search_terms['Name'])
    item_selector.search_results = results

 

But, on the last line, where I try to actually display the results in the Search results part of the widget, I get an error. 

AttributeError: can't set attribute

Error found at line 12 in cell 44.

 

Is there anything I can do to actually display the results from my search query in the search results box? 

 

Link to comment
Share on other sites

  • Seeq Team

Hi Nitish,

I was able to run your code successfully after tchanging the property in your spy.search to be Name since your if statement only works if the property searched for include Name. Even when having the Data ID as the property, running the code didn't return an error, just no search results. Can you send your full code and what version of SPy you're using by running spy.__version__

Link to comment
Share on other sites

Hi Kristopher,

I am using SeeQ version 190.3

You are right, I checked and found that the code runs without errors now.

What I wanted to do was to have my own search function run when the users clicks the Search button. But I don't see any events in the documentation. Question is - is it possible to do a custom search using this widget? 

I do have another plugin now using ipyvuetify which basically does the same thing, so it's ok if this is not possible. 

Link to comment
Share on other sites

  • Seeq Team

Feel free to use the ipywidgets code instead. The spy.widgets are built on top of ipywidgets to make it easier for people to use but if you're already using ipywidgets, go ahead. If you're looking for a new challenge, you can try using the ipyvuetify library, which has more modern widgets but can often be more difficult to learn and use than ipywidgets.

Link to comment
Share on other sites

  • Seeq Team

Hey Nitish, 

You can update the _search_seeq method of that widget by creating a new class, your custom search widget that inherits all the capabilities of the default one, then override the search function.

Something like this should do it:

class ChrisSeeqItemSelect(spy.widgets.SeeqItemSelect):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        
    def _search_seeq(self, search_terms):
        if self._debug:
            print(f'Seeq Search Terms:\n{search_terms}')

        if not search_terms:
            self._found_seeq_items = None
        else:
            try:
                self._found_seeq_items = spy.search({'ID': search_terms['Name']}, all_properties = True)
            except RuntimeError as e:
                if 'No datasource found' in str(e):
                    self._found_seeq_items = None
                else:
                    raise
        if self._debug:
            print(f'Items returned from Seeq:\n{self._found_seeq_items}')
            
item_selector = ChrisSeeqItemSelect(
    title = '<H2>Tag Search by UID</H2>',
    show_fields = ['Name'],
    item_type = 'Signal',
    results_box_rows = 15, 
    max_displayed_results = 20
)

display(item_selector)

You can then access the `search_results` with `item_selector.search_results`.

Let us know how it goes!

-Chrisimage.png

 

Link to comment
Share on other sites

Thanks Chris. I'll try this.

Next thing I'll need is, when a user clicks on a search result, I should add it to the list of signals in the worksheet. 

Can you please let me know where I can see the code for the SeeqItemSelect widget? 

Otherwise, please give me the function which handles the onClick event on the search results. 

Link to comment
Share on other sites

I was able to package the attahced file into an addon. So, the user can open the addon, and search for signals using a customised search. The user can then click on one  of the signals. This signal shows up in the users worksheet. 

But, it removes all the old signals that the user had already selected, and which were on the users list. 

How do I retain the old signals while adding the new one to the list? 

 

SearchWidget.ipynb

Link to comment
Share on other sites

  • Seeq Team

Hi Nitish, 

You can review the source code with something like this:

import inspect
lines = inspect.getsource(spy.widgets.SeeqItemSelect)
print(lines)

(pulled from Stack Overflow here: https://stackoverflow.com/questions/427453/how-can-i-get-the-source-code-of-a-python-function

As for updating the Worksheets from where the user launched the Add-on from, you'll need to use spy.workbooks, rather than spy.push. 

Something like this should work: 

url = 'https://develop.seeq.dev/workbook/0EECCDF4-FD70-F910-BDEE-87D647287803/worksheet/0EECCDF5-0134-EEC0-9B95-13CDFBA98737'
workbookId = '0EECCDF4-FD70-F910-BDEE-87D647287803'
worksheetId = '0EECCDF5-0134-EEC0-9B95-13CDFBA98737'
wb = spy.workbooks.pull(spy.workbooks.search({'ID': workbookId}))

signalID_toadd = 'CD732D0B-C3BA-496F-B69E-55543944B5F1'
signal_search_df = spy.search({'ID': signalID_toadd})
new_display_items = pd.concat([wb[0].worksheets[0].display_items, signal_search_df], ignore_index=True)
wb[0].worksheets[0].display_items = new_display_items

_push = spy.workbooks.push(wb)

 

Also, if you are trying to make an Add-on to search by ID, I would suggest raising this as a support request for our product team to consider adding this capability to our existing search functionality, by creating a ticket here: https://seeq.atlassian.net/servicedesk/customer/portal/3 if you have not already. Thanks!

-Chris

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...