Skip to content

Commit

Permalink
Improve search with multi type results
Browse files Browse the repository at this point in the history
  • Loading branch information
Nice3point committed Jan 29, 2025
1 parent 0f68d17 commit 9f2e2ef
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public sealed class MockDecompositionSearchService : IDecompositionSearchService
}
finally
{
if (selectedObject is not null)
if (query == string.Empty)
{
_previousSelection = null;
}
else if (selectedObject is not null)
{
_previousSelection = selectedObject;
}
Expand Down Expand Up @@ -113,10 +117,11 @@ private static List<ObservableDecomposedMember> FilterMembers(string query, List

private ObservableDecomposedObject? FindPreviousSelectedType(List<ObservableDecomposedObject> decomposedObjects)
{
if (_previousSelection is null) return null;

ObservableDecomposedObject? fetchedObject = null;
foreach (var decomposedObject in decomposedObjects)
{
if (_previousSelection is null) break;
if (decomposedObject.TypeFullName != _previousSelection.TypeFullName) continue;
if (decomposedObject.Members.Count == 0) continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ async partial void OnSelectedDecomposedObjectChanged(ObservableDecomposedObject?
if (value is null) return;

await FetchMembersAsync(value);
if (FilteredDecomposedObjects.Count > 1)
{
value.FilteredMembers = value.Members;
return;
}

value.FilteredMembers = searchService.SearchMembers(SearchText, value);
}
catch (Exception exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ async partial void OnSelectedDecomposedObjectChanged(ObservableDecomposedObject?
if (value is null) return;

await FetchMembersAsync(value);
if (FilteredDecomposedObjects.Count > 1)
{
value.FilteredMembers = value.Members;
return;
}

value.FilteredMembers = searchService.SearchMembers(SearchText, value);
}
catch (Exception exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public sealed class DecompositionSearchService : IDecompositionSearchService
}
finally
{
if (selectedObject is not null)
if (query == string.Empty)
{
_previousSelection = null;
}
else if (selectedObject is not null)
{
_previousSelection = selectedObject;
}
Expand Down Expand Up @@ -113,10 +117,11 @@ private static List<ObservableDecomposedMember> FilterMembers(string query, List

private ObservableDecomposedObject? FindPreviousSelectedType(List<ObservableDecomposedObject> decomposedObjects)
{
if (_previousSelection is null) return null;

ObservableDecomposedObject? fetchedObject = null;
foreach (var decomposedObject in decomposedObjects)
{
if (_previousSelection is null) break;
if (decomposedObject.TypeFullName != _previousSelection.TypeFullName) continue;
if (decomposedObject.Members.Count == 0) continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ async partial void OnSelectedDecomposedObjectChanged(ObservableDecomposedObject?
if (value is null) return;

await FetchMembersAsync(value);
if (FilteredDecomposedObjects.Count > 1)
{
value.FilteredMembers = value.Members;
return;
}

value.FilteredMembers = searchService.SearchMembers(SearchText, value);
}
catch (InvalidObjectException exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ async partial void OnSelectedDecomposedObjectChanged(ObservableDecomposedObject?
if (value is null) return;

await FetchMembersAsync(value);
if (FilteredDecomposedObjects.Count > 1)
{
value.FilteredMembers = value.Members;
return;
}

value.FilteredMembers = searchService.SearchMembers(SearchText, value);
}
catch (Exception exception)
Expand Down

0 comments on commit 9f2e2ef

Please sign in to comment.