Example #1
0
        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");
        }
Example #2
0
        /// <summary>
        /// Add a property criterion to a search unit.
        /// set to the left or to the right operand of the expression.
        /// </summary>
        /// <param name="criteria"></param>
        /// <param name="keyText"></param>
        /// <returns></returns>
        public SearchPropCriterionKeyText AddCritPropKeyText(SearchEntity searchEntity, SearchPropBoolExpr boolExprParent, BoolExprOperand leftOrRight, string keyText)
        {
            if (searchEntity == null)
            {
                return(null);
            }
            if (boolExprParent == null)
            {
                return(null);
            }

            // check the text
            if (string.IsNullOrWhiteSpace(keyText))
            {
                return(null);
            }

            // check that the criterion does not already exists
            if (boolExprParent.GetLeftOrRight(leftOrRight) != null)
            {
                return(null);
            }

            SearchPropCriterionKeyText criterionPropKeyText = CreateSearchPropCriterionPropKeyText(keyText);

            // set the prop operand to the left or to the right
            boolExprParent.SetLeftOrRight(leftOrRight, criterionPropKeyText);
            return(criterionPropKeyText);
        }
Example #3
0
        /// <summary>
        /// add it as the root criterion of the unit.
        /// </summary>
        /// <param name="searchEntityUnit"></param>
        /// <param name="keyText"></param>
        /// <returns></returns>
        public SearchPropCriterionKeyText AddCritPropKeyText(SearchEntity searchEntity, string keyText)
        {
            if (searchEntity == null)
            {
                return(null);
            }

            // check the text
            if (string.IsNullOrWhiteSpace(keyText))
            {
                return(null);
            }

            // check that a root criterion does not already exists
            if (searchEntity.SearchPropRoot != null)
            {
                // a criterion already exists!
                return(null);
            }

            SearchPropCriterionKeyText criterionPropKeyText = CreateSearchPropCriterionPropKeyText(keyText);

            searchEntity.SearchPropRoot = criterionPropKeyText;
            return(criterionPropKeyText);
        }
        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");
        }
Example #5
0
        /// <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);
            }
        }
Example #7
0
        private SearchPropCriterionKeyText CreateSearchPropCriterionPropKeyText(string keyText)
        {
            SearchPropCriterionKeyText criterionPropKeyText = new SearchPropCriterionKeyText();

            criterionPropKeyText.KeyText         = keyText;
            criterionPropKeyText.PropKeyTextType = CritOptionPropKeyTextType.AllKeyType;

            // key can be a string or textCode
            criterionPropKeyText.PropKeyType = CritOptionPropKeyType.All;

            criterionPropKeyText.TextMatch     = CritOptionTextMatch.TextMatchExact;
            criterionPropKeyText.TextSensitive = CritOptionTextSensitive.Yes;

            // go (or not) inside prop group childs if exists
            // TODO: FindFirst, FindAll
            criterionPropKeyText.PropChildsScan = CritOptionPropChildsScan.GoInsidePropGroupChilds;

            return(criterionPropKeyText);
        }
Example #8
0
        /// <summary>
        /// Create all work objet matching object, recursivly.
        /// </summary>
        /// <param name="searchPropBase"></param>
        /// <returns></returns>
        private SearchPropBaseWork CreateAllSearchPropBaseWork(SearchPropBase searchPropBase)
        {
            // a bool expr, go inside left and right part
            SearchPropBoolExpr searchPropBoolExpr = searchPropBase as SearchPropBoolExpr;

            if (searchPropBoolExpr != null)
            {
                SearchPropBoolExprWork searchPropBoolExprWork = new SearchPropBoolExprWork();
                searchPropBoolExprWork.SearchPropBaseId = searchPropBoolExpr.Id;
                searchPropBoolExprWork.Operator         = searchPropBoolExpr.Operator;

                // create work object on the left side
                searchPropBoolExprWork.LeftOperand = CreateAllSearchPropBaseWork(searchPropBoolExpr.LeftOperand);

                // create work object on the right side
                searchPropBoolExprWork.RightOperand = CreateAllSearchPropBaseWork(searchPropBoolExpr.RightOperand);

                return(searchPropBoolExprWork);
            }

            // a final criterion
            SearchPropCriterionKeyText propCritKeyText = searchPropBase as SearchPropCriterionKeyText;

            if (propCritKeyText != null)
            {
                SearchPropCriterionKeyTextWork propCritKeyTextWork = new SearchPropCriterionKeyTextWork();
                propCritKeyTextWork.SearchPropBaseId = propCritKeyText.Id;
                propCritKeyTextWork.KeyText          = propCritKeyText.KeyText;
                propCritKeyTextWork.PropChildsScan   = propCritKeyText.PropChildsScan;
                propCritKeyTextWork.PropKeyTextType  = propCritKeyText.PropKeyTextType;
                propCritKeyTextWork.TextMatch        = propCritKeyText.TextMatch;
                propCritKeyTextWork.TextSensitive    = propCritKeyText.TextSensitive;

                return(propCritKeyTextWork);
            }
            // TODO: others final criterion type


            // not implemented
            throw new Exception("Search property not yet implemented!");
        }