Exemple #1
0
        /// <summary>
        /// テーブルJoin(検索条件複雑な場合、SQL自動生成できない!)シンプルな検索条件が必要
        /// メリット:
        /// 1.SQL不要(場合によるデメリットになる)
        /// 2.データモデル自動作成する(カスタムズメソッド追加も可能)
        /// 3.単純なDMLは使いやすい(効率で実行するのため、個別実装が必要)
        /// 4.必要な場合のみ、データアクセス発生するので、無駄なデータアクセスは避けることができる
        ///     (開発者はLINQの仕様をよく理解するが必要)
        /// デメリット、制約条件:
        /// 1.シンプルな検索条件が必要
        /// 2.Sql Linq式にカスタム関数が使えない
        /// 3.データエンティティのデータ保護が足りない(個別対応が必要)
        /// 4.複雑な検索(例えばjoin,groupなど使う場合)、LINQ式の方がわかりにくい、チューニングが難しい
        /// 5. 抽出結果の型は匿名クラスになると、関数の戻り値として返せない(型変換が必要)
        /// 6.LINQ式が動的な生成できない(この場合、直接にSQLでアクセスは補助手段としてが必要)
        /// 7.プログラムの柔軟性は比較的に乏しい
        /// 8.データモデルは自動生成するため、チューニングははぼできない
        /// 9.大規模、複雑な処理、高い効率が必要の場合、リスクが高い
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="mode"></param>
        /// <param name="opts"></param>
        /// <returns>戻り値はEntitySetを使用することよりソードなどDataSet並みの機能が持っている</returns>
        public static EntitySet <TableList> Search(string keyword, SearchModes mode, SearchOptions opts)
        {
            EntitySet <TableList> result = new EntitySet <TableList>();

            using (LiveDataContext live = new LiveDataContext(CurrentConnection))
            {
                if (string.IsNullOrEmpty(keyword))
                {
                    result.SetSource(live.TableList.ToList());
                    return(result);
                }
                keyword = keyword.Replace(" ", " ");
                //全件のデータをまず抽出する(検索条件にカスタム関数が存在するため)
                //検索条件に個別関数IsMatchを使用する
                //IQueryableからIEnumerableに変換する必要がある(この処理は実際C#の方でやる)
                var source = from t in live.TableList.AsEnumerable()
                             join c in live.TableLayoutInfo.AsEnumerable() on
                             t.TableName equals c.TableName
                             where IsMatch(keyword, t, c, mode, opts)
                             group t by t.TableName into g
                             orderby g.Key
                             select g.First();

                //toListを呼び出し場合、実際のデータアクセスが発生する
                result.SetSource(source.ToList());

                return(result);
            }
        }
        public async Task <PagedResult <EmployerSearchModel> > SearchAsync(string searchText,
                                                                           int currentPage,
                                                                           SearchTypes searchType,
                                                                           int pageSize        = 20,
                                                                           string searchFields = null,
                                                                           string selectFields = null,
                                                                           string orderBy      = null,
                                                                           Dictionary <string, Dictionary <object, long> > facets = null,
                                                                           string filter          = null,
                                                                           string highlights      = null,
                                                                           SearchModes searchMode = SearchModes.Any)
        {
            var result = new PagedResult <EmployerSearchModel>();

            result.Results = new List <EmployerSearchModel>(_documents);
            //result.ActualRecordTotal = _documents.Count;
            //result.VirtualRecordTotal = _documents.Count;

            var totalRecords = _documents.Count;

            //Return the results
            var searchResults = new PagedResult <EmployerSearchModel>
            {
                Results            = result.Results,
                CurrentPage        = currentPage,
                PageSize           = pageSize,
                ActualRecordTotal  = totalRecords,
                VirtualRecordTotal = totalRecords
            };

            return(searchResults);
        }
Exemple #3
0
        public static T GetComponentInHierarchy <T>(this GameObject gameObject, SearchModes mode) where T : class
        {
            T t;

            switch (mode)
            {
            case SearchModes.Parent:
            case SearchModes.Parents:
                t = gameObject.GetComponentInParent <T>();
                break;

            case SearchModes.Self:
                t = gameObject.GetComponent <T>();
                break;

            case SearchModes.Child:
            case SearchModes.Children:
                t = gameObject.GetComponentInChildren <T>();
                break;

            default:
                t = null;
                break;
            }

            return(t);
        }
        public void AssignReceived(SyncBlockSettings newSettings, NanobotBuildAndRepairSystemPriorityHandling buildPriority)
        {
            _AllowBuild     = newSettings.AllowBuild;
            _UseIgnoreColor = newSettings.UseIgnoreColor;
            _IgnoreColor    = newSettings.IgnoreColor;
            _UseGrindColor  = newSettings.UseGrindColor;
            _GrindColor     = newSettings.GrindColor;
            _ShowArea       = newSettings.ShowArea;

            _AreaWidthLeft    = newSettings.AreaWidthLeft;
            _AreaWidthRight   = newSettings.AreaWidthRight;
            _AreaHeightTop    = newSettings.AreaHeightTop;
            _AreaHeightBottom = newSettings.AreaHeightBottom;
            _AreaDepthFront   = newSettings.AreaDepthFront;
            _AreaDepthRear    = newSettings.AreaDepthRear;

            _BuildPriority = newSettings.BuildPriority;

            _ScriptControlled = newSettings.ScriptControlled;
            _SoundVolume      = newSettings.SoundVolume;
            _SearchMode       = newSettings.SearchMode;
            _WorkMode         = newSettings.WorkMode;

            RecalcAreaBoundigBox();
            buildPriority.SetEntries(BuildPriority);

            Changed = 2u;
        }
Exemple #5
0
 public StringScanner(ModuleDefMD module, string[] stringList, SearchModes searchMode)
 {
     this.module     = module;
     this.stringList = stringList;
     this.searchMode = searchMode;
     if (searchMode == SearchModes.CaseInsensitive)
     {
         stringList = stringList.Select(s => s.ToLowerInvariant()).ToArray();
     }
 }
Exemple #6
0
        static void Search(string args)
        {
            int         index      = 0;
            bool        dirs       = false;
            bool        files      = true;
            bool        curdir     = false;
            SearchModes searchMode = SearchModes.nameonly;

            if (args.Length < 1)
            {
                Console.WriteLine(SearchHelp); return;
            }
            searchMode = (SearchModes)LoadInt(args, ref index);
            //curdir = LoadBool(args, true, ref index);
            //files = LoadBool(args, true, ref index);
            //dirs = LoadBool(args, true, ref index);
            string searchtext = args.Remove(0, index).Trim();
            List <KeyValuePair <int, IID> > values = new List <KeyValuePair <int, IID> >();

            if (curdir)
            {
                selected.Search(searchtext, dirs, files, values);
            }
            else
            {
                Program.CentralDirectory.Search(searchtext, dirs, files, values);
            }
            if (files && !dirs)
            {
                foreach (var a in values.OrderByDescending(n => n.Key))
                {
                    var b = a.Value as SoftFile;
                    Console.Write(a.Key + "|"); PrintFiles(b.Name, b.Id, 10, 10);
                }
            }
            else
            if (!files && dirs)
            {
                foreach (var a in values.OrderByDescending(n => n.Key))
                {
                    var b = a.Value as SoftDirectory;
                    Console.WriteLine($"{a.Key}|{b.Name} ({b.Id})");
                }
            }
            else
            if (files && dirs)
            {
                foreach (var a in values)
                {
                    var b = a.Value as IID;
                    Console.WriteLine($"{a.Key}|{b.Id}");
                }
            }
        }
Exemple #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            string        keyword = this.txtSearch.Text;
            SearchModes   mode    = (SearchModes)this.cmbSearchMode.SelectedValue;
            SearchOptions opts    = (this.chkTableName.Checked ? SearchOptions.TableName : SearchOptions.None) |
                                    (this.chkColumn.Checked ? SearchOptions.ColumnName : SearchOptions.None) |
                                    (this.chkComment.Checked ? SearchOptions.CommentName : SearchOptions.None);

            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource          = LinqSqlHelp.Search(keyword, mode, opts);
        }
        public void ReloadGUI(SearchModes mode)
        {
            SearchMode = mode;

            grdSearch.DataSource = null;
            grdSearch.DataBind();
            grdSearch.Visible = false;

            txtSearch.Text = string.Empty;
            txtSearch.Focus();

            lblRequirement.Visible = false;
        }
Exemple #9
0
        private static bool IsMatch(string keyword, TableList t, TableLayoutInfo c, SearchModes mode, SearchOptions opts)
        {
            bool result = false;

            if ((opts & SearchOptions.TableName) == SearchOptions.TableName)
            {
                result = Match(t.TableName, keyword, mode) || Match(t.TableDisplayName, keyword, mode);
            }

            if ((opts & SearchOptions.ColumnName) == SearchOptions.ColumnName)
            {
                result = result || Match(c.ColumnName, keyword, mode) || Match(c.ColumnDisplayName, keyword, mode);
            }
            if ((opts & SearchOptions.CommentName) == SearchOptions.CommentName)
            {
                result = result || Match(t.Comment, keyword, SearchModes.Contain) || Match(c.Comment, keyword, SearchModes.Contain);
            }
            return(result);
        }
        public PokemonSearchSettings()
        {
            SpeciesValue = 1;

            TypeValue     = PokemonTypes.Normal;
            NatureValue   = 0;
            AbilityValue  = 1;
            HeldItemValue = 0;
            PokeBallValue = 4;
            PokerusValue  = PokerusStatuses.None;
            RibbonValue   = PokemonRibbons.Any;

            Stat                 = StatTypes.HP;
            IV                   = StatTypes.HP;
            EV                   = StatTypes.HP;
            Condition            = ConditionTypes.Cool;
            StatComparison       = ComparisonTypes.Equal;
            IVComparison         = ComparisonTypes.Equal;
            EVComparison         = ComparisonTypes.Equal;
            ConditionComparison  = ComparisonTypes.Equal;
            LevelComparison      = ComparisonTypes.Equal;
            FriendshipComparison = ComparisonTypes.Equal;
            LevelValue           = 1;
            FamilyValue          = 1;

            Move1Value = 0;
            Move2Value = 0;
            Move3Value = 0;
            Move4Value = 0;

            HiddenPowerDamageComparison = ComparisonTypes.Equal;
            HiddenPowerDamageValue      = 30;
            HiddenPowerTypeValue        = PokemonTypes.Fighting;

            EggGroupValue = EggGroups.Field;

            SortMethod = SortMethods.None;
            SortOrder  = SortOrders.HighestToLowest;
            SearchMode = SearchModes.NewSearch;

            GameIndex = -1;
        }
        public SyncBlockSettings()
        {
            _AllowBuild       = true;
            _UseIgnoreColor   = false;
            _IgnoreColor      = Vector3.Zero;
            _UseGrindColor    = false;
            _GrindColor       = Vector3.Zero;
            _ShowArea         = false;
            _BuildPriority    = string.Empty;
            _ScriptControlled = false;
            _SoundVolume      = NanobotBuildAndRepairSystemBlock.WELDER_SOUND_VOLUME / 2;
            _SearchMode       = SearchModes.Grids;
            _WorkMode         = WorkModes.WeldBeforeGrind;

            Changed          = 0;
            _LastStored      = MyAPIGateway.Session.ElapsedPlayTime;
            _LastTransmitted = MyAPIGateway.Session.ElapsedPlayTime;

            RecalcAreaBoundigBox();
        }
Exemple #12
0
        private static bool isMatch(string src, string target)
        {
            if (string.IsNullOrEmpty(src))
            {
                return(false);
            }
            string[] keywords;

            if (target.Contains(" "))
            {
                keywords = target.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                keywords = new string[] { target };
            }
            string x = src.ToLower();
            //string y = target.ToLower();
            SearchModes mode = SearchModes.Contain;

            switch (mode)
            {
            case SearchModes.Contain:
                return(keywords.All(y => x.Contains(y.ToLower())));

            case SearchModes.ForwardMatch:
                return(keywords.All(y => x.StartsWith(y.ToLower())));

            case SearchModes.BackwardMatch:
                return(keywords.All(y => x.EndsWith(y.ToLower())));

            case SearchModes.Equale:
                return(x.Equals(target.ToLower()));

            default:
                break;
            }

            return(false);
        }
 public void setSearchMode(SearchModes smSearchMode)
 {
     cbSearchMode.SelectedItem = smSearchMode;
 }
Exemple #14
0
        public static T[] GetComponentsInHierarchy <T>(this GameObject gameObject, SearchModes mode, List <GameObject> customObjects = null) where T : class
        {
            T[] components;

            switch (mode)
            {
            case SearchModes.Parent:
                //return the first component found in parent
                T parentComponent = gameObject.GetComponentInParent <T>();
                if (parentComponent != null)
                {
                    components    = new T[1];
                    components[0] = parentComponent;
                }
                else
                {
                    components = new T[0];
                }
                break;

            case SearchModes.Parents:
                //return all components found in parent
                components = gameObject.GetComponentsInParent <T>();
                break;

            default:
            case SearchModes.Self:
                //just return the components on this object
                components = gameObject.GetComponents <T>();
                break;

            case SearchModes.Child:
                //return the first component found in children
                T childComponent = gameObject.GetComponentInChildren <T>();
                if (childComponent != null)
                {
                    components    = new T[1];
                    components[0] = childComponent;
                }
                else
                {
                    components = new T[0];
                }
                break;

            case SearchModes.Children:
                //return all components found in children
                components = gameObject.GetComponentsInChildren <T>();
                break;

            case SearchModes.Custom:
                //return all components attached to objects in the custom list
                if (customObjects == null)
                {
                    components = new T[0];
                }
                else
                {
                    List <T> customTs = new List <T>(customObjects.Count);
                    for (int i = 0; i < customObjects.Count; i++)
                    {
                        if (customObjects[i] == null)
                        {
                            continue;
                        }
                        T[] coTs = customObjects[i].GetComponents <T>();
                        for (int j = 0; j < coTs.Length; j++)
                        {
                            customTs.Add(coTs[j]);
                        }
                    }
                    components = customTs.ToArray();
                }
                break;
            }

            return(components);
        }
Exemple #15
0
 public StringScanner(ModuleDefMD module, SearchModes searchMode)
 {
     this.module     = module;
     this.searchMode = searchMode;
 }
        /// <summary>
        /// Instigate a search
        /// </summary>
        /// <remarks>
        /// Intended for use by FindDialog or FindForm only
        /// </remarks>
        internal bool Search()
        {
            // Set up new event args. 'First' flag is set depending on the display mode of the find form
            SearchEventArgs eventArgs = new SearchEventArgs(SearchRegularExpression, SearchMode == FindDialog.SearchModes.Ready);
            if (searchRequested == null)
            {
                throw new Exception("No search event supplied");
            }
            searchRequested(this, eventArgs);

            // set the state of the search form depending on the result of the search
            if (eventArgs.Successful)
            {
                SearchMode = SearchModes.SearchAgain;
                return true;
            }
            if (eventArgs.FirstSearch)
            {
                SearchMode = SearchModes.SearchFailed;
            }
            else
            {
                SearchMode = SearchModes.SearchFinished;
            }
            return false;
        }
        /// <summary>
        ///     Executes an advanced search using pagination, sorting, filters, facets, and highlighting.
        /// </summary>
        /// <param name="searchText">The text used for the search. When empty all results are returned.</param>
        /// <param name="totalRecords">The returned total number of records in the results</param>
        /// <param name="currentPage">The current page of results to return</param>
        /// <param name="pageSize">The size of the result set to return (default=20). Maximum is 1000.</param>
        /// <param name="filter">
        ///     A set of comma or semicolon separated field names to searching.
        ///     Only fields marked with the 'IsSearchable' attribute can be included.
        ///     The default is empty and all searchable fields will be searched.
        ///     ///
        /// </param>
        /// <param name="selectFields"></param>
        /// A set of comma or semicolon separated field names to return values for.
        /// Default is empty and will return all field values
        /// <param name="orderBy">
        ///     A set of comma or semicolon separated sort terms.
        ///     Default is empty and will return results sorted by score relevance.
        ///     For example, OrganisationName, SicName DESC
        ///     Only fields marked with the 'IsSortable' attribute can be included.
        /// </param>
        /// <param name="facets">
        ///     Specifies the facets to query and returns the facet results
        ///     The default is empty and no facets will be applied.
        ///     Only fields marked with the 'IsFacetable' attribute can be included.
        ///     Call by specifing field names as keys in the dictionary.
        ///     The resulting dictionary for each field returns all possible values and their count for that field.
        ///     ///
        /// </param>
        /// <param name="filter">
        ///     A filter expression using OData syntax (see
        ///     https://docs.microsoft.com/en-us/rest/api/searchservice/odata-expression-syntax-for-azure-search)
        ///     The default is empty and no filter will be applied.
        ///     Only fields marked with the 'IsFilterable' attribute can be included.
        ///     String comparisons are case sensitive.
        ///     You can also use the operators '==','!=', '>=', '>', '<=', '<', '&&', '||' which will be automatically replaced with OData counterparts 'EQ','NE', 'GE', 'GT', 'LE', 'LT', 'AND', 'OR'.
        /// Special functions also include search.in(myfield, 'a, b, c')
        /// /// </param>
        /// <param name="highlights">
        ///     A set of comma or semicolon separated field names used for hit highlights.
        ///     Only fields marked with the 'IsSearchable' attribute can be included.
        ///     By default, Azure Search returns up to 5 highlights per field.
        ///     The limit is configurable per field by appending -
        ///     <max # of highlights>
        ///         following the field name.
        ///         For example, highlight=title-3,description-10 returns up to 3 highlighted hits from the title field and up to
        ///         10 hits from the description field. <max # of highlights> must be an integer between 1 and 1000 inclusive.
        /// </param>
        public async Task <PagedResult <EmployerSearchModel> > SearchAsync(string searchText,
                                                                           int currentPage,
                                                                           SearchTypes searchType,
                                                                           int pageSize        = 20,
                                                                           string searchFields = null,
                                                                           string selectFields = null,
                                                                           string orderBy      = null,
                                                                           Dictionary <string, Dictionary <object, long> > facets = null,
                                                                           string filter          = null,
                                                                           string highlights      = null,
                                                                           SearchModes searchMode = SearchModes.Any)
        {
            if (Disabled)
            {
                throw new Exception($"{nameof(AzureEmployerSearchRepository)} is disabled");
            }

            var indexClient = await _indexClient.Value;

            // Execute search based on query string
            var sp = new SearchParameters
            {
                SearchMode = searchMode.Equals("any") ? SearchMode.Any : SearchMode.All,
                Top        = pageSize,
                Skip       = (currentPage - 1) * pageSize,
                IncludeTotalResultCount = true,
                QueryType = QueryType.Simple
            };

            //Specify the fields to search
            if (!string.IsNullOrWhiteSpace(searchFields))
            {
                sp.SearchFields = searchFields.SplitI().ToList();
            }

            //Limit result fields
            if (!string.IsNullOrWhiteSpace(selectFields))
            {
                sp.Select = selectFields.SplitI().ToList();
            }

            // Define the sort type or order by relevance score
            if (!string.IsNullOrWhiteSpace(orderBy) && !orderBy.EqualsI("Relevance", "Relevance desc", "Relevance asc"))
            {
                sp.OrderBy = orderBy.SplitI().ToList();
            }

            // Add filtering
            sp.Filter = string.IsNullOrWhiteSpace(filter) ? null : filter;

            //Add facets
            if (facets != null && facets.Count > 0)
            {
                sp.Facets = facets.Keys.ToList();
            }

            //Execute the search
            var
                results = await indexClient.Documents.SearchAsync <EmployerSearchModel>(searchText, sp);

            //Return the total records
            var totalRecords = results.Count.Value;

            /* There are too many empty searches being executed (about 1200). This needs further investigation to see if/how they can be reduced */
            if (!string.IsNullOrEmpty(searchText))
            {
                var telemetryProperties = new Dictionary <string, string>
                {
                    { "TimeStamp", VirtualDateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") },
                    { "QueryTerms", searchText },
                    { "ResultCount", totalRecords.ToString() },
                    { "SearchType", searchType.ToString() },
                    { "SearchParameters", HttpUtility.UrlDecode(sp.ToString()) }
                };

                _telemetryClient?.TrackEvent("Gpg_Search", telemetryProperties);

                await SearchLog.WriteAsync(telemetryProperties);
            }

            //Return the facet results
            if (sp.Facets != null && sp.Facets.Any())
            {
                foreach (var facetGroupKey in results.Facets.Keys)
                {
                    if (facets[facetGroupKey] == null)
                    {
                        facets[facetGroupKey] = new Dictionary <object, long>();
                    }

                    foreach (var facetResult in results.Facets[facetGroupKey])
                    {
                        facets[facetGroupKey][facetResult.Value] = facetResult.Count.Value;
                    }
                }
            }

            //Return the results
            var searchResults = new PagedResult <EmployerSearchModel>
            {
                Results            = results.Results.Select(r => r.Document).ToList(),
                CurrentPage        = currentPage,
                PageSize           = pageSize,
                ActualRecordTotal  = totalRecords,
                VirtualRecordTotal = totalRecords
            };

            return(searchResults);
        }
 public void setSearchMode(SearchModes smSearchMode)
 {
     cbSearchMode.SelectedItem = smSearchMode;
 }
Exemple #19
0
 /// <summary>
 /// Handle search mode changes
 /// </summary>
 private void OnSearchModeChanged(SearchModes oldValue, SearchModes newValue)
 {
     UpdateInteraction();
 }