public void TextExtensionMethods(SearcherContext context, string query, string methodName, int count, int index) { var db = new GraphElementSearcherDatabase(Stencil) .AddExtensionMethods(typeof(GraphElementSearcherDatabaseTests)) .Build(); var results = db.Search(query, out _); Assert.AreEqual(count, results.Count); var item = results[index] as ISearcherItemDataProvider; Assert.NotNull(item); if (context == SearcherContext.Graph) { Assert.IsTrue(results[index] is GraphNodeModelSearcherItem); } else { Assert.IsTrue(results[index] is StackNodeModelSearcherItem); } var data = (MethodSearcherItemData)item.Data; Assert.AreEqual(SearcherItemTarget.Method, data.Target); Assert.AreEqual(methodName, data.MethodInfo.Name); }
public void TestProperties(SearcherContext context, string query, string propertyName, int index, int count) { var db = new GraphElementSearcherDatabase(Stencil) .AddProperties(typeof(FakeObject).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)) .Build(); var results = db.Search(query, out _); Assert.AreEqual(count, results.Count); var item = results[index] as ISearcherItemDataProvider; Assert.NotNull(item); if (context == SearcherContext.Graph) { Assert.IsTrue(results[index] is GraphNodeModelSearcherItem); } else { Assert.IsTrue(results[index] is StackNodeModelSearcherItem); } var data = (PropertySearcherItemData)item.Data; Assert.AreEqual(SearcherItemTarget.Property, data.Target); Assert.AreEqual(propertyName, data.PropertyInfo.Name); }
public void TestControlFlows(SearcherContext context, Type loopType, string query, int count, int index) { var db = new GraphElementSearcherDatabase(Stencil) .AddControlFlows() .Build(); var results = db.Search(query, out _); Assert.AreEqual(count, results.Count); var item = results[index] as ISearcherItemDataProvider; Assert.IsNotNull(item); var data = (ControlFlowSearcherItemData)item.Data; Assert.AreEqual(SearcherItemTarget.ControlFlow, data.Target); Assert.AreEqual(loopType, data.Type); if (context == SearcherContext.Graph) { Assert.IsTrue(results[index] is GraphNodeModelSearcherItem); } else { Assert.IsTrue(results[index] is StackNodeModelSearcherItem); } }
public void TestMethods(SearcherContext context, string query, string methodName) { var db = new GraphElementSearcherDatabase(Stencil) .AddMethods(typeof(FakeObject).GetMethods(BindingFlags.Public | BindingFlags.Instance)) .Build(); var results = db.Search(query, out _); Assert.AreEqual(1, results.Count); var item = results[0] as ISearcherItemDataProvider; Assert.NotNull(item); if (context == SearcherContext.Graph) { Assert.IsTrue(results[0] is GraphNodeModelSearcherItem); } else { Assert.IsTrue(results[0] is StackNodeModelSearcherItem); } var data = (MethodSearcherItemData)item.Data; Assert.AreEqual(SearcherItemTarget.Method, data.Target); Assert.AreEqual(methodName, data.MethodInfo.Name); }
public void TestNodesWithSearcherItemAttributes(SearcherContext context, string query, Type type, SpawnFlags mode) { var db = new GraphElementSearcherDatabase(Stencil) .AddNodesWithSearcherItemAttribute() .Build(); var results = db.Search(query, out _); var item = (ISearcherItemDataProvider)results[0]; var data = (NodeSearcherItemData)item.Data; Assert.AreEqual(SearcherItemTarget.Node, data.Target); Assert.AreEqual(type, data.Type); if (context == SearcherContext.Graph) { Assert.IsTrue(results[0] is GraphNodeModelSearcherItem); CreateNodesAndValidateGraphModel((GraphNodeModelSearcherItem)item, mode, initialNodes => { var node = GraphModel.NodeModels.FirstOrDefault(n => n.GetType() == type); Assert.IsNotNull(node); Assert.AreEqual(initialNodes.Count + 1, GraphModel.NodeModels.Count); }); } else { Assert.IsTrue(results[0] is StackNodeModelSearcherItem); CreateNodesAndValidateStackModel((StackNodeModelSearcherItem)item, mode, (initialGraphNodes, stack) => { var node = stack.NodeModels.FirstOrDefault(n => n.GetType() == type); Assert.IsNotNull(node); Assert.AreEqual(stack.NodeModels.Count(), 1); Assert.AreEqual(initialGraphNodes.Count, GraphModel.NodeModels.Count); }); } }
/// <summary> /// Indexes the text into database, /// if contains searchwords, they all are indexed after adding the text to db. /// Updates the existing searchwords to link to this text /// </summary> /// <param name="text"> /// Provided text to be indexed /// </param> /// <returns> /// boolean with value depending if text indexing was succesfull /// </returns> public bool IndexText(Texts text) { try { using (var db = new SearcherContext()) { //Storing searchwords before adding text to db var listOfSearchwordsToAdd = text.SearchWords; text.SearchWords = null; db.Texts.Add(text); //new text added to db db.SaveChanges(); //If it contained searchwords, now they will be indexed. if (listOfSearchwordsToAdd.Count > 0) { foreach (var searchWord in listOfSearchwordsToAdd) { IndexSearchWord(searchWord); } } //finding all searchwords that are in text var searchwords = db.SearchWords.Where(s => text.text.Contains(s.SearchWord)).ToList(); //Updating these searchwords in database foreach (var searchword in searchwords) { IndexSearchWord(searchword); } return(true); } } catch (Exception) { return(false); } }
public void TestFields(SearcherContext context, string query, string fieldName, int index, int count, bool isConstant) { var db = new GraphElementSearcherDatabase(Stencil) .AddFields(typeof(FakeObject).GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)) .Build(); var results = db.Search(query, out _); Assert.AreEqual(count, results.Count); var item = results[index] as ISearcherItemDataProvider; Assert.NotNull(item); if (context == SearcherContext.Graph) { Assert.IsTrue(results[index] is GraphNodeModelSearcherItem); var graphItem = (GraphNodeModelSearcherItem)results[index]; var node = graphItem.CreateElements.Invoke(new GraphNodeCreationData(GraphModel, Vector2.down)).First(); Assert.That(node is ISystemConstantNodeModel, NUnit.Framework.Is.EqualTo(isConstant)); } else { Assert.IsTrue(results[index] is StackNodeModelSearcherItem); } var data = (FieldSearcherItemData)item.Data; Assert.AreEqual(SearcherItemTarget.Field, data.Target); Assert.AreEqual(fieldName, data.FieldInfo.Name); }
/// <summary> /// Initializes a new instance of the SearcherItemAttribute class. /// </summary> /// <param name="stencilType">Type of Stencil to use to create the element.</param> /// <param name="context">Search context where this item should figure.</param> /// <param name="path">Path of the item in the searcher.</param> public SearcherItemAttribute(Type stencilType, SearcherContext context, string path) { Assert.IsTrue( stencilType.IsSubclassOf(typeof(Stencil)), $"Parameter stencilType is type of {stencilType.FullName} which is not a subclass of {typeof(Stencil).FullName}"); StencilType = stencilType; Path = path; Context = context; }
public SearcherItemAttribute(Type stencilType, SearcherContext context, string path) { Assert.IsTrue( stencilType.IsSubclassOf(typeof(Stencil)), $"Parameter stencilType is type of {stencilType} which is not a subclass of UnityEditor.VisualScripting.Model.Stencils.Stencil"); StencilType = stencilType; Path = path; Context = context; }
/// <summary> /// Searches for texts in db who are linked to searchword with /// equal word as provided parameter /// </summary> /// <param name="searchword"> /// provided string with /// </param> /// <returns> /// List of texts linked to searchwords /// </returns> public List <Texts> SearchTextsWithString(string searchword) { using (var db = new SearcherContext()) { return((from t in db.Texts where t.SearchWords.Contains(t.SearchWords.FirstOrDefault(x => x.SearchWord == searchword)) select t) //For now I do not include searchwords, as they cause endless loop in json or xml, //as they also have words, who also have search words etc.. //.Include(texts => texts.SearchWords) .ToList()); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); Searcher = new SearcherContext(FSDirectory.Open(HostingEnvironment.MapPath("~/App_Data/Index")), new WhitespaceAnalyzer()); }
/// <summary> /// Indexes a searchword, finds all texts containig it and adds /// a connection to database between seachword and text. /// </summary> /// <param name="searchword"> /// Provided searchword /// </param> /// <returns> /// boolean with value depending if indexing was succesfull /// </returns> public bool IndexSearchWord(SearchWords searchword) { try { using (var db = new SearcherContext()) { //List of texts containing searchword List <Texts> texts = db.Texts.Where(t => t.text.Contains(searchword.SearchWord)) .Include(t => t.SearchWords) .ToList(); foreach (var text in texts) { bool update = true; //For each loop checks if there is already such searchword for this text foreach (var searchWordInText in text.SearchWords) { if (searchWordInText.SearchWord.Contains(searchword.SearchWord)) { update = false; } } //If there is no such search word for text, it is indexed if (update) { //Fiding the actual searchword from table SearchWords existingSearchword = db.SearchWords.FirstOrDefault(s => s.SearchWord.Equals(searchword.SearchWord)); if (existingSearchword != null) { text.SearchWords.Add(existingSearchword); db.Entry(text).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } else { text.SearchWords.Add(searchword); db.Entry(text).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } } } return(true); } catch (Exception) { return(false); } }
/// <summary> /// Searches for texts that are linked to provided parameter /// in database /// </summary> /// <param name="searchwords"> /// Provided list of searchwords /// </param> /// <returns> /// Empty list if exception occured or if no results found, /// List with strings sorted descening by occurance of searchwords in text /// </returns> public List <string> SearchTextsWithList(List <string> searchwords) { try { using (var db = new SearcherContext()) { List <Texts> listOfFoundTexts = new List <Texts>(); Dictionary <int, int> textsWithSearchwordCount = new Dictionary <int, int>(); //Foreach loop for provided list of words foreach (var searchword in searchwords) { //Finding list of text for item in list var textList = (from c in db.Texts where c.SearchWords.Contains(c.SearchWords.FirstOrDefault(x => x.SearchWord == searchword)) select c).ToList(); //going throught every text in found list foreach (var text in textList) { //If dictionary has the key of found text id, then adds to its value if (textsWithSearchwordCount.ContainsKey(text.id)) { textsWithSearchwordCount[text.id] += 1; } //If dictionary has no key of found text id, then adds key and value of 1 else { textsWithSearchwordCount.Add(text.id, 1); listOfFoundTexts.Add(text); } } } //Descending sorting of values in dictionary var items = from pair in textsWithSearchwordCount orderby pair.Value descending select pair; List <string> listOfFoundStrings = new List <string>(); foreach (KeyValuePair <int, int> pair in items) { //Adding the strings from texts to list in previously sorted manner listOfFoundStrings.Add(listOfFoundTexts.FirstOrDefault(t => t.id == pair.Key).text); } return(listOfFoundStrings); } } catch (Exception ex) { return(new List <string>()); } }
public void TestSingleItem(SearcherContext context, string query, CommonSearcherTags expectedTag) { var db = new GraphElementSearcherDatabase(Stencil, GraphModel) .AddStickyNote() .Build(); var results = db.Search(query); if (context == SearcherContext.Graph) { Assert.That(results[0], NUnit.Framework.Is.TypeOf <GraphNodeModelSearcherItem>()); var item = (GraphNodeModelSearcherItem)results[0]; Assert.That(item.Data, NUnit.Framework.Is.TypeOf <TagSearcherItemData>()); var tag = (TagSearcherItemData)item.Data; Assert.That(tag.Tag, NUnit.Framework.Is.EqualTo(expectedTag)); } }
public void TestUnaryOperators(SearcherContext context, string query, UnaryOperatorKind kind, SpawnFlags mode) { var db = new GraphElementSearcherDatabase(Stencil) .AddUnaryOperators() .Build(); var results = db.Search(query, out _); Assert.AreEqual(1, results.Count); var item = results[0] as ISearcherItemDataProvider; Assert.IsNotNull(item); var data = (UnaryOperatorSearcherItemData)item.Data; Assert.AreEqual(SearcherItemTarget.UnaryOperator, data.Target); Assert.AreEqual(kind, data.Kind); if (context == SearcherContext.Graph) { Assert.IsTrue(results[0] is GraphNodeModelSearcherItem); CreateNodesAndValidateGraphModel((GraphNodeModelSearcherItem)item, mode, initialNodes => { var node = GraphModel.NodeModels.OfType <UnaryOperatorNodeModel>().FirstOrDefault(); Assert.IsNotNull(node); Assert.AreEqual(kind, node.Kind); Assert.AreEqual(initialNodes.Count + 1, GraphModel.NodeModels.Count); }); } else { Assert.IsTrue(results[0] is StackNodeModelSearcherItem); CreateNodesAndValidateStackModel((StackNodeModelSearcherItem)item, mode, (initialGraphNodes, stack) => { var node = stack.NodeModels.OfType <UnaryOperatorNodeModel>().FirstOrDefault(); Assert.IsNotNull(node); Assert.AreEqual(kind, node.Kind); Assert.AreEqual(1, stack.NodeModels.Count()); Assert.AreEqual(initialGraphNodes.Count, GraphModel.NodeModels.Count); }); } }
public void TestSingleItem(SearcherContext context, string query, SearcherItemTarget target) { var db = new GraphElementSearcherDatabase(Stencil) .AddInlineExpression() .AddStack() .AddEmptyFunction() .AddStickyNote() .Build(); var results = db.Search(query, out _); if (context == SearcherContext.Graph) { Assert.IsTrue(results[0] is GraphNodeModelSearcherItem); } else { Assert.IsTrue(results[0] is StackNodeModelSearcherItem); } Assert.AreEqual(target, ((ISearcherItemDataProvider)results[0]).Data.Target); }
public void AddUserActionEvent(string searchKeywords, SearcherContext context, UserActionKind kind) { if (m_LastNodeCreation == null) // TODO: context is not handled yet, ie. edge-to-stack { return; } if (m_UserActionEvents == null) { m_UserActionEvents = new Queue <VSUserActions>(); } var vsUserActions = new VSUserActions { vsUserSearchQuery = searchKeywords, vsUserCreateNode = m_LastNodeCreation.NodeTitle, vsVersion = k_VisualScriptingVersion, vsSearcherContext = context.ToString(), }; vsUserActions.SetResult(m_LastNodeCreation.NodeTitle == null ? NodeCreationEvent.Cancel : NodeCreationEvent.Keep); Log($"AddUserActionEvent {kind} {vsUserActions}"); switch (kind) { case UserActionKind.SendImmediately: m_UserActionEvents.Enqueue(vsUserActions); break; case UserActionKind.WaitForConfirmation: m_LastNodeCreation.Action = vsUserActions; break; default: throw new ArgumentOutOfRangeException(nameof(kind), kind, null); } }
public EcsSearcherFilter(SearcherContext context) : base(context) { }
public TestFilter(SearcherContext context) : base(context) { }
public UnitOfWork(SearcherContext context) { _context = context; _repositories = new ConcurrentDictionary <Type, object>(); _disposed = false; }
static string GetFilterKey(SearcherContext context, SearcherItemTarget target) { return($"{context}_{target}"); }
public SearcherFilter(SearcherContext context) { m_Context = context; m_Filters = new Dictionary <string, List <Func <ISearcherItemData, bool> > >(); }
public ContentService(SearcherContext context) { _context = context; }