public void SearchEntities_PropKeyEqualsName() { EtagairCore core = Common.CreateCore(RepositConfig); //==== creates entities, with prop //----create entities Entity toshibaCoreI7 = core.Editor.CreateEntity(); core.Editor.CreateProperty(toshibaCoreI7, "Name", "Toshiba Satellite Core I7"); core.Editor.CreateProperty(toshibaCoreI7, "TradeMark", "Toshiba"); //==== define the search: from the root folder, select all entities having a key prop called 'Name' SearchEntity searchEntities = core.Searcher.CreateSearchEntity(SearchFolderScope.All); //--Add single criteria: property key text equals to 'Name' SearchPropCriterionKeyText criterion = core.Searcher.AddCritPropKeyText(searchEntities, "Name"); criterion.PropKeyTextType = CritOptionPropKeyTextType.AllKeyType; criterion.TextSensitive = CritOptionTextSensitive.No; criterion.TextMatch = CritOptionTextMatch.TextMatchExact; //==== execute the search, get the result: list of found entities SearchEntityResult result = core.Searcher.ExecSearchEntity(searchEntities); // check found entities Assert.AreEqual(1, result.ListEntityId.Count, "One found entities expected"); bool found; found = result.ListEntityId.Contains(toshibaCoreI7.Id); Assert.IsTrue(found, "The entity id toshibaCoreI7 should be selected"); }
public void SearchEntities_DefinedFolders_2_OnePropKeyEqualsName_E_F1_2E_F2_2E() { EtagairCore core = Common.CreateCore(RepositConfig); //==== creates entities, with prop //----create entities Entity toshibaCoreI7 = core.Editor.CreateEntity(); core.Editor.CreateProperty(toshibaCoreI7, "Name", "Toshiba Satellite Core I7"); core.Editor.CreateProperty(toshibaCoreI7, "TradeMark", "Toshiba"); //---- create a folder, under the root Folder foldComputers = core.Editor.CreateFolder(null, "computers"); Entity dellCoreI7 = core.Editor.CreateEntity(foldComputers); core.Editor.CreateProperty(dellCoreI7, "Name", "Dell Inspiron 15-5570-sku6"); core.Editor.CreateProperty(dellCoreI7, "TradeMark", "Dell"); Entity HPCoreI7 = core.Editor.CreateEntity(foldComputers); core.Editor.CreateProperty(HPCoreI7, "Nom", "HP Core i7"); core.Editor.CreateProperty(HPCoreI7, "TradeMark", "HP"); //---- create a folder, under the root Folder foldOthers = core.Editor.CreateFolder(null, "others"); Entity asusCoreI7 = core.Editor.CreateEntity(foldOthers); core.Editor.CreateProperty(asusCoreI7, "Name", "Asus Core i7"); core.Editor.CreateProperty(asusCoreI7, "TradeMark", "Asus"); //==== define the search: from the root folder, select all entities having a key prop called 'Name' SearchEntity searchEntities = core.Searcher.CreateSearchEntity(SearchFolderScope.Defined); //--Add sources folders, set option: go inside folders childs core.Searcher.AddSourceFolder(searchEntities, foldComputers, true); // add a second source folder core.Searcher.AddSourceFolder(searchEntities, foldOthers, true); //--Add single criteria: property key text equals to 'Name' SearchPropCriterionKeyText criterion = core.Searcher.AddCritPropKeyText(searchEntities, "Name"); criterion.TextMatch = CritOptionTextMatch.TextMatchExact; criterion.PropKeyTextType = CritOptionPropKeyTextType.AllKeyType; //==== execute the search, get the result: list of found entities SearchEntityResult result = core.Searcher.ExecSearchEntity(searchEntities); // check found entities Assert.AreEqual(2, result.ListEntityId.Count, "2 found entity expected"); bool found; found = result.ListEntityId.Contains(dellCoreI7.Id); Assert.IsTrue(found, "The entity id dellCoreI7 should be selected"); found = result.ListEntityId.Contains(asusCoreI7.Id); Assert.IsTrue(found, "The entity id asusCoreI7 should be selected"); }
/// <summary> /// Search entities by the key property. /// Create 3 entities, select entities having a property key equals to 'Name'. /// /// computers\ /// Ent: Name=Toshiba Ok, selected /// Ent: Name=Dell Ok, selected /// Ent: Company=HP --NOT selected /// /// -------output: /// Db initialized with success. /// -Search result: nb= 2 /// Ent, id: 5c6822abdd125603e885d8d4 /// Ent, id: 5c6822c1dd125603e885d8d6 /// </summary> public void CreateThreeEntitiesSearchPropKeyName() { EtagairEngine engine = CreateEngine(); //---- create a folder, under the root Folder foldComputers = engine.Editor.CreateFolder(null, "computers"); //==== creates entities, with prop //----create entity Entity toshibaCoreI7 = engine.Editor.CreateEntity(foldComputers); engine.Editor.CreateProperty(toshibaCoreI7, "Name", "Toshiba Satellite Core I7"); engine.Editor.CreateProperty(toshibaCoreI7, "TradeMark", "Toshiba"); //----create entity Entity dellCoreI7 = engine.Editor.CreateEntity(foldComputers); engine.Editor.CreateProperty(dellCoreI7, "Name", "Dell Inspiron 15-5570-sku6"); engine.Editor.CreateProperty(dellCoreI7, "TradeMark", "Dell"); //----create entity Entity HPCoreI7 = engine.Editor.CreateEntity(foldComputers); engine.Editor.CreateProperty(HPCoreI7, "Company", "HP Core i7"); engine.Editor.CreateProperty(HPCoreI7, "TradeMark", "HP"); //==== define the search: from the root folder, select all entities having a key prop called 'Name' SearchEntity searchEntities = engine.Searcher.CreateSearchEntity("EntitiesHavingPropName", SearchFolderScope.Defined); //--Add sources folders, set option: go inside folders childs // (only one for now is managed!!) engine.Searcher.AddSourceFolder(searchEntities, foldComputers, true); //--Add criteria: (a boolean expression) SearchPropCriterionKeyText criterion = engine.Searcher.AddCritPropKeyText(searchEntities, "Name"); criterion.TextMatch = CritOptionTextMatch.TextMatchExact; criterion.PropKeyTextType = CritOptionPropKeyTextType.AllKeyType; //==== execute the search, get the result: list of found entities SearchEntityResult result = engine.Searcher.ExecSearchEntity(searchEntities); // displays found entities Console.WriteLine("-Search result: nb=" + result.ListEntityId.Count); foreach (string entityId in result.ListEntityId) { // displays the id of the entity Console.WriteLine("Ent, id: " + entityId); // load the entity and display it Entity entity = engine.Searcher.FindEntityById(entityId); // display the properties of the entity.... } }
// TODO: gérer trad finale absente -> selectionne la mainLang // exp: pas de texte en fr_FR mais existe en fr, prend ce dernier. /// <summary> /// select entities having a property key='Name' /// /// computers\ /// Ent: Name=Toshiba Ok, selected /// Ent: Name=Dell Ok, selected /// Ent: Company=HP --NOT selected /// /// </summary> /// <param name="core"></param> static void TestSearchEntity(EtagairCore core) { Console.WriteLine("====>TestSearchEntity: "); //---- create a folder, under the root Folder foldComputers = core.Editor.CreateFolder(null, "computers"); //==== creates entities, with prop //----create entity Entity toshibaCoreI7 = core.Editor.CreateEntity(foldComputers); core.Editor.CreateProperty(toshibaCoreI7, "Name", "Toshiba Satellite Core I7"); core.Editor.CreateProperty(toshibaCoreI7, "TradeMark", "Toshiba"); //----create entity Entity dellCoreI7 = core.Editor.CreateEntity(foldComputers); core.Editor.CreateProperty(dellCoreI7, "Name", "Dell Inspiron 15-5570-sku6"); core.Editor.CreateProperty(dellCoreI7, "TradeMark", "Dell"); //----create entity Entity HPCoreI7 = core.Editor.CreateEntity(foldComputers); core.Editor.CreateProperty(HPCoreI7, "Company", "HP Core i7"); core.Editor.CreateProperty(HPCoreI7, "TradeMark", "HP"); //==== define the search: from the root folder, select all entities having a key prop called 'Name' SearchEntity searchEntities = core.Searcher.CreateSearchEntity(SearchFolderScope.Defined); //--Add sources folders, set option: go inside folders childs core.Searcher.AddSourceFolder(searchEntities, foldComputers, true); //--Add criteria: (a boolean expression) SearchPropCriterionKeyText criterion = core.Searcher.AddCritPropKeyText(searchEntities, "Name"); criterion.PropKeyTextType = CritOptionPropKeyTextType.AllKeyType; criterion.TextMatch = CritOptionTextMatch.TextMatchExact; //--set options // TODO: lesquelles? //==== execute the search, get the result: list of found entities SearchEntityResult result = core.Searcher.ExecSearchEntity(searchEntities); // displays found entities Console.WriteLine("-Search result: nb=" + result.ListEntityId.Count); foreach (string entityId in result.ListEntityId) { // load the entity Console.WriteLine("Ent, id: " + entityId); } }
/// <summary> /// Process, execute the search entity definition. /// Scan folder, one by one. /// </summary> public SearchEntityResult Process(SearchEntity searchEntity) { // create the result object SearchEntityResult result = new SearchEntityResult(); // scan each source folder foreach (SearchEntitySrcFolder srcFolder in searchEntity.ListSearchEntitySrcFolder) { // get the folder object Folder folder = _reposit.Finder.FindFolderById(srcFolder.FolderId); // create a work/exec object of the criteria expression //SearchPropBaseWork searchPropBaseWork = CreateAllSearchPropBaseWork(searchEntity.SearchPropRoot); // search entities under the folder parent SearchInFolder(searchEntity, folder, srcFolder.GoInsideChilds, result); } // returns the final results return(result); }
/// <summary> /// Process the final criterion: property key text is matching? /// </summary> /// <param name="propCritKeyTextWork"></param> /// <param name="entity"></param> /// <param name="result"></param> /// <returns></returns> public bool AnalyzeEntityOnCritKeyText(SearchPropCriterionKeyTextWork propCritKeyTextWork, Entity entity, SearchEntityResult result) { // scan all properties of the entity to match the criterion: key name AnalyzeEntityOnCritKeyText_PropGroup(entity.PropertyRoot, propCritKeyTextWork); // todo: rajouter un flag dans le work: Match: yes,no, NotSet // todo: si match=true, alors stocker l'entité (l'id) dans le result if (propCritKeyTextWork.PropertyMatch == PropertyMatch.Yes) { result.AddEntity(entity); } return(true); }
/// <summary> /// analyze the criteria properties expression for the entity /// </summary> /// <param name="entity"></param> /// <returns></returns> private bool AnalyzeEntityOnCriteria(SearchEntity searchEntity, Entity entity, SearchEntityResult result) { // create a work/exec object of the criteria expression SearchPropBaseWork searchPropBaseWork = CreateAllSearchPropBaseWork(searchEntity.SearchPropRoot); // a bool expr, go inside left and right part SearchPropBoolExprWork searchPropBoolExprWork = searchPropBaseWork as SearchPropBoolExprWork; if (searchPropBoolExprWork != null) { // create work object on the left side // create work object on the right side //return searchPropBoolExprWork; // ok, no error return(true); } // a final criterion SearchPropCriterionKeyTextWork propCritKeyTextWork = searchPropBaseWork as SearchPropCriterionKeyTextWork; if (propCritKeyTextWork != null) { EntitySearcherPropKeyText searcherPropKeyText = new EntitySearcherPropKeyText(_reposit); return(searcherPropKeyText.AnalyzeEntityOnCritKeyText(propCritKeyTextWork, entity, result)); } // TODO: others final criterion type // not implemented throw new Exception("Search property not yet implemented!"); }
/// <summary> /// search entities under the folder parent. /// </summary> /// <param name="searchEntity"></param> /// <param name="folder"></param> /// <param name="result"></param> /// <returns></returns> private bool SearchInFolder(SearchEntity searchEntity, Folder folder, bool goInsideChilds, SearchEntityResult result) { // process each entity in the folder source foreach (KeyValuePair <string, ObjectType> pair in folder.ListChildId) { // is it a folder? if (pair.Value == ObjectType.Folder) { // go inside this folder child? if (goInsideChilds) { // load the folder object Folder folderChild = _reposit.Finder.FindFolderById(pair.Key); SearchInFolder(searchEntity, folderChild, true, result); // process next object continue; } } // is it an entity? if (pair.Value == ObjectType.Entity) { // load the entity Entity entity = _reposit.Finder.FindEntityById(pair.Key); // analyze the criteria properties expression for the entity AnalyzeEntityOnCriteria(searchEntity, entity, result); } // others cases: entity or folder template: do nothing } return(true); }