Unity-Technologies / com.unity.selection-groups

Other
117 stars 9 forks source link

QuickSearch/Unity Search goql provider issues #264

Closed MostHated closed 1 year ago

MostHated commented 2 years ago

Hey there, I have ran into a few issues attempting to use goql as a provider for the Search system. The one that gave me trouble first was that "toObject" is missing from the provider. I had to copy/paste it into a new provider and give it the ID "com.unity.goqlcustom" (why such a long provider id? Most are a letter, or 4, simply goql: would be much more inline and easier to type and use).

At first I tried to add it in the most basic manner:

I added it to the following location https://github.com/Unity-Technologies/com.unity.selection-groups/blob/5a5421b5c48cd528569741a0dbea7fad3cea5d36/GoQL/Editor/GoQLSearchProvider.cs#L56

  toObject = (item, context) => ObjectFromItem(item), 

But then I noticed that when I tried to actually use it in a TableView I was building, and trying to get the name from the toObject call using a SearchSelector for creating a column/header and populating the column with the name of the object, the names I was getting back from the gameobject didn't match the actual path that was coming back in the description field. The description was right, as was the object that was selected when clicking on an entry in the list, but the name kept coming back as a completely different object (ones that didn't even match the search query).

// This was returning the wrong GameObject name
[SearchSelector("name", provider: providerId), UsedImplicitly]
internal static object GetName(SearchItem item) => item.ToObject<GameObject>().name;

So I went back to the provider and changed the label field to instead return the gameobject name as the path that was returned via the description field was already fine with me:

fetchLabel = (item, context) =>
                {
                    GameObject go = ObjectFromItem(item);
                    return go.name;
                },

After this change, and using the label field in my table, it was displaying the proper name:

static IEnumerable<SearchColumn> CreateColumns(float colWidth, float windowWidth = 400f)
        {
            var lastColWidth = windowWidth - 56f - 30f - 60f - colWidth - 15f;
            // const string propertyProvider = "Experimental/SerializedProperty";
            yield return CreateSearchColumn("Enabled", "enabled", "GameObject/Enabled", null, columnFlags, 56f, SearchColumnFlags.TextAlignmentCenter);
            yield return CreateSearchColumn("Ico", "thumbnail", null, null, columnFlags, 30f, SearchColumnFlags.TextAlignmentCenter);
            yield return CreateSearchColumn("Size", "goSize", null, null, columnFlags, 60f);
            yield return CreateSearchColumn("Name", "label", null, null, columnFlags, colWidth); // This now displayed the correct name
            yield return CreateSearchColumn("Location", "description", null, null, columnFlags, lastColWidth);
        }

Thanks, -MH

sindharta commented 2 years ago

Please clarify if I misunderstand, but it sounds like the issue that you are having is more on the com.unity.quicksearch side, rather than goql ?

MostHated commented 2 years ago

Well, the issue is with (GoQLSearchProvider.cs). So, I guess technically it is less an issue with goql itself, and more of an issue with how goql is being used in conjunction with QuickSearch's SearchProvider apis. Though, I had assumed it would be considered a goql issue, as the SearchProvider is included with this package. Is that not the case in this instance?

sindharta commented 2 years ago

Well, the issue is with (GoQLSearchProvider.cs).

Please let me clarify. Are you trying to improve the existing GoQLSearchProvider.cs, but are currently having problems with how to integrate it better with com.unity.quick-search ?

MostHated commented 2 years ago

My apologies, I somehow missed your reply.

The main reason for having created this issue is to provide feedback based on my attempt to use the search provider. I wanted to bring attention to some aspects of the search provider that I felt were important, but missing or returned unexpected results compared to how other default search provider implementations functioned. I was demonstrating some of the changes I had made, which I felt made it operate more in line with how other providers worked, in hopes that similar changes might be able to be implemented into the GoQL search provider to enhance its usability. The main one being that most other search providers, if you have a SearchItem object and you call the .toObject() method, it returns the actual object, but the toObject implementation seems to be missing. So if you use the GoQL search provider to search for a GameObject, there was no way I could find currently to actually obtain that GameObject from the search results (when using the search results via code).

sindharta commented 2 years ago

(when using the search results via code).

Could you please share us your code so that we can understand the problem ?

sindharta commented 1 year ago

Closing due to non-activity. Feel free to reopen when necessary.