Skip to content

Commit

Permalink
Cherry-Pick DYN-6148 Dynamo Library Lucene Search (#14315)
Browse files Browse the repository at this point in the history
* Fix Node Autocomplete Regressions (#14275)

* Fix Node Autocomplete Regressions

Due that we are adding ZeroTouchNodes during test mode around 9 tests are failing, seems that there are several nodes duplicates so each test needs to be analyzed separately.
Then in this fix I'm reverting the code for adding ZeroTouchNodes and also removing a test that will fail due to this change.

* Fix Node Autocomplete Regressions

Re-adding unit test with Failure category

* DYN-6148 Dynamo Library Lucene Search (#14287)

* DYN-6148 Dynamo Library Lucene Search

Implementing the use of Lucene Search in the Dynamo Library

* DYN-6148 Dynamo Library Lucene Search

Fixing calls to LuceneSearchUtility for using the Lucene Singleton.

* DYN-6148 Dynamo Library Lucene Search

Removing extra space and removing unused usings

* DYN-6148 Dynamo Library Lucene Search Regressions

The SearchNodeTest() test was moved to DynamoLibraryItemsTest due that in the LibraryResourceProviderTests we are not creating the DynamoModel (also there is no way to get the DynamoModel) so the Lucene Singleton is not created and is crashing.
Also I did some minor changes in the test due that the FullName contains the category (so instead of  "dyf://123.456.somepackage.{nodeName}" was replaced by "dyf://Core.Input.{nodeName}" otherwise the Code Block node is not found).
  • Loading branch information
RobertGlobant20 authored Aug 24, 2023
1 parent a1f03b1 commit 77790f0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 39 deletions.
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

0 comments on commit 77790f0

Please sign in to comment.