Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-6148 Dynamo Library Lucene Search #14287

Merged
merged 5 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public SearchResultDataProvider(NodeSearchModel model, IconResourceProvider icon
public override Stream GetResource(string searchText, out string extension)
{
var text = Uri.UnescapeDataString(searchText);
var elements = model.Search(text, 0, null);
var elements = model.Search(text, LuceneSearch.LuceneUtilityNodeSearch);
extension = "json";
return GetNodeItemDataStream(elements, true);
}
Expand Down
56 changes: 55 additions & 1 deletion test/ViewExtensionLibraryTests/DynamoLibraryItemsTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Dynamo;
using Dynamo.Controls;
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Interfaces;
using Dynamo.LibraryViewExtensionWebView2.Handlers;
using Dynamo.LibraryViewExtensionWebView2;
using Dynamo.Search.SearchElements;
using Dynamo.Search;
using Dynamo.Utilities;
using Dynamo.ViewModels;
using Dynamo.Wpf.Interfaces;
using Moq;
Expand All @@ -27,6 +34,53 @@ protected override void GetLibrariesToPreload(List<string> libraries)
libraries.Add("DSCoreNodes.dll");
base.GetLibrariesToPreload(libraries);
}

[Test]
[Category("UnitTests")]
public void SearchNodeTest()
{
var nodeSearchModel = new NodeSearchModel();
var path = @"C:\temp\xyz.dyf";
var nodeName = "Code Block";
var expectedQualifiedName = $"dyf://Core.Input.{nodeName}";

for (int i = 0; i < 100; i++)
{
nodeSearchModel.Add(
new CustomNodeSearchElement(new Mock<ICustomNodeSource>().Object,
new CustomNodeInfo(Guid.NewGuid(), $"Node-{i}", $"Node-{i}-Category{i}", $"Node-{i}-Description", path))
);
}

nodeSearchModel.Add(
new CustomNodeSearchElement(new Mock<ICustomNodeSource>().Object,
new CustomNodeInfo(Guid.NewGuid(), nodeName, "Core.Input", "Node-Description", path))
);

var pathmanager = new Mock<IPathManager>();
var iconProvider = new IconResourceProvider(pathmanager.Object);

SearchResultDataProvider searchResultDataProvider = new SearchResultDataProvider(nodeSearchModel, iconProvider);

var extension = string.Empty;
var searchResultStream = searchResultDataProvider.GetResource(nodeName, out extension);

var searchResult = GetLoadedTypesFromJson(searchResultStream);
List<LoadedTypeItem> nodesResult = searchResult.loadedTypes;

Assert.AreEqual(nodesResult.Count, 1);
Assert.AreEqual(expectedQualifiedName, nodesResult[0].fullyQualifiedName);
}

private LoadedTypeData<LoadedTypeItem> GetLoadedTypesFromJson(Stream stream)
{
using (var sr = new StreamReader(stream))
{
var serializer = new JsonSerializer();
return (LoadedTypeData<LoadedTypeItem>)serializer.Deserialize(sr, typeof(LoadedTypeData<LoadedTypeItem>));
}
}

/*
[Test]
[Category("UnitTests"), Category("Failure")]
Expand Down
38 changes: 1 addition & 37 deletions test/ViewExtensionLibraryTests/LibraryResourceProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,43 +326,7 @@ public void CustomNodeSearchElementLoadedType()
Assert.AreEqual(IconUrl.DefaultIcon, url.Name);
Assert.AreEqual(IconUrl.DefaultPath, url.Path);
}

[Test]
[Category("UnitTests")]
public void SearchNodeTest()
{
var nodeSearchModel = new NodeSearchModel();
var path = @"C:\temp\xyz.dyf";
var nodeName = "Code Block";
var expectedQualifiedName = $"dyf://123.456.somepackage.{nodeName}";

for (int i = 0; i < 100; i++)
{
nodeSearchModel.Add(
new CustomNodeSearchElement(new Mock<ICustomNodeSource>().Object,
new CustomNodeInfo(Guid.NewGuid(), $"Node-{i}", $"Node-{i}-Category{i}", $"Node-{i}-Description", path))
);
}

nodeSearchModel.Add(
new CustomNodeSearchElement(new Mock<ICustomNodeSource>().Object,
new CustomNodeInfo(Guid.NewGuid(), nodeName, "123.456.somepackage", "Node-Description", path))
);

var pathmanager = new Mock<IPathManager>();
var iconProvider = new IconResourceProvider(pathmanager.Object);

SearchResultDataProvider searchResultDataProvider = new SearchResultDataProvider(nodeSearchModel, iconProvider);

var extension = string.Empty;
var searchResultStream = searchResultDataProvider.GetResource(nodeName, out extension);

var searchResult = GetLoadedTypesFromJson(searchResultStream);
List<LoadedTypeItem> nodesResult = searchResult.loadedTypes;

Assert.AreEqual(nodesResult.Count, 1);
Assert.AreEqual(expectedQualifiedName, nodesResult[0].fullyQualifiedName);
}


private LoadedTypeData<LoadedTypeItem> GetLoadedTypesFromJson(Stream stream)
{
Expand Down