Пример #1
0
        public TableSearchFilter(IVsSearchQuery searchQuery, IWpfTableControl control)
        {
            this.tokens  = new List <string>();
            this.columns = new List <ITableColumnDefinition>(control.ColumnStates.Count);

            foreach (IVsSearchToken token in SearchUtilities.ExtractSearchTokens(searchQuery) ?? Array.Empty <IVsSearchToken>())
            {
                if (!string.IsNullOrEmpty(token.ParsedTokenText))
                {
                    this.tokens.Add(token.ParsedTokenText);
                }
            }

            foreach (ColumnState2 columnState in control.ColumnStates.OfType <ColumnState2>())
            {
                if (columnState.IsVisible || columnState.GroupingPriority > 0)
                {
                    ITableColumnDefinition definition = control.ColumnDefinitionManager.GetColumnDefinition(columnState.Name);
                    if (definition != null)
                    {
                        this.columns.Add(definition);
                    }
                }
            }
        }
Пример #2
0
        protected override void BeginProcessing()
        {
            ICollection <BankTrx> colMatches      = null;
            ICollection <BankTrx> colExactMatches = null;
            bool blnExactMatch = false;

            Register.MatchNormalCore(
                lngNumber: Number,
                datDate: Date,
                intDaysBefore: DaysBefore,
                intDaysAfter: DaysAfter,
                strDescription: Description,
                curAmount: Amount,
                curMatchMin: MatchMin,
                curMatchMax: MatchMax,
                blnLooseMatch: LooseMatch,
                colMatches: ref colMatches,
                colExactMatches: ref colExactMatches,
                blnExactMatch: ref blnExactMatch);
            SearchUtilities.PruneToExactMatches(colExactMatches, Date, ref colMatches, ref blnExactMatch);
            foreach (BankTrx objTrx in colMatches)
            {
                WriteObject(objTrx);
            }
        }
            public SearchFilter(IVsSearchQuery searchQuery, IWpfTableControl control)
            {
                _searchTokens = SearchUtilities.ExtractSearchTokens(searchQuery);
                if (_searchTokens == null)
                {
                    _searchTokens = Array.Empty <IVsSearchToken>();
                }

                var newVisibleColumns = new List <ITableColumnDefinition>();

                foreach (var c in control.ColumnStates)
                {
                    if (c.IsVisible || ((c as ColumnState2)?.GroupingPriority > 0))
                    {
                        var definition = control.ColumnDefinitionManager.GetColumnDefinition(
                            c.Name
                            );
                        if (definition != null)
                        {
                            newVisibleColumns.Add(definition);
                        }
                    }
                }

                _visibleColumns = newVisibleColumns;
            }
Пример #4
0
        public void GetMinOverlapOffset_SingleBin_NullChunks()
        {
            const ulong minOffset = 3591443256775;
            const ulong maxOffset = 3591443312067;

            long observedResults = SearchUtilities.GetMinOverlapOffset(null, minOffset, maxOffset);

            Assert.Equal(0, observedResults);
        }
Пример #5
0
        public TableSearchFilter(IVsSearchQuery searchQuery, IWpfTableControl control)
        {
            _searchTokens = SearchUtilities.ExtractSearchTokens(searchQuery) ?? Array.Empty <IVsSearchToken>();

            var newVisibleColumns = control.ColumnStates
                                    .Where(c => c.IsVisible || (c as ColumnState2)?.GroupingPriority > 0)
                                    .Select(c => control.ColumnDefinitionManager.GetColumnDefinition(c.Name))
                                    .Where(definition => definition != null).ToList();

            _visibleColumns = newVisibleColumns;
        }
Пример #6
0
        public void GetMaxOffset_MissingAllOverlappingBins_ReturnMaxOffset()
        {
            const ulong expectedResults = ulong.MaxValue;

            var idToChunks = new Dictionary <int, Interval[]>();

            var   refSeq          = new ReferenceIndex(ChromosomeUtilities.Chr2, idToChunks, null);
            ulong observedResults = SearchUtilities.GetMaxOffset(refSeq, 243171329);

            Assert.Equal(expectedResults, observedResults);
        }
Пример #7
0
        public void GetMinOverlapOffset_SingleBin()
        {
            const long  expectedResults = 3591443256857;
            const ulong minOffset       = 3591443256775;
            const ulong maxOffset       = 3591443312067;

            var chunks = new[] { new Interval(3591443256857, 3591443311984) };

            long observedResults = SearchUtilities.GetMinOverlapOffset(chunks, minOffset, maxOffset);

            Assert.Equal(expectedResults, observedResults);
        }
Пример #8
0
        public void GetMaxOffset_MissingBin()
        {
            const ulong expectedResults = 3724057593420;

            var idToChunks = new Dictionary <int, Interval[]>
            {
                [6878] = new[] { new Interval(3724057593420, 3724057615020) }
            };

            var   refSeq          = new ReferenceIndex(ChromosomeUtilities.Chr2, idToChunks, null);
            ulong observedResults = SearchUtilities.GetMaxOffset(refSeq, 35962881);

            Assert.Equal(expectedResults, observedResults);
        }
Пример #9
0
        public void GetMaxOffset_MissingFirstBin()
        {
            const ulong expectedResults = 3724908138137;

            var idToChunks = new Dictionary <int, Interval[]>
            {
                [860] = new[] { new Interval(3724908138137, 3724908155075) }
            };

            var   refSeq          = new ReferenceIndex(ChromosomeUtilities.Chr2, idToChunks, null);
            ulong observedResults = SearchUtilities.GetMaxOffset(refSeq, 36028417);

            Assert.Equal(expectedResults, observedResults);
        }
Пример #10
0
        public void GetMaxOffset_Nominal()
        {
            const ulong expectedResults = 3591443312067;

            var idToChunks = new Dictionary <int, Interval[]>
            {
                [6311] = new[] { new Interval(3591443312067, 3592132724129) }
            };

            var   refSeq          = new ReferenceIndex(ChromosomeUtilities.Chr2, idToChunks, null);
            ulong observedResults = SearchUtilities.GetMaxOffset(refSeq, 26699126);

            Assert.Equal(expectedResults, observedResults);
        }
Пример #11
0
        public void GetMinMaxFileOffset_Nominal()
        {
            var intervals = new []
            {
                new Interval(3, 3),
                new Interval(2, 2),
                new Interval(1, 5),
                new Interval(5, 10),
                new Interval(2, 6),
                new Interval(8, 9)
            };

            (long observedMinOffset, long observedMaxOffset) = SearchUtilities.GetMinMaxVirtualFileOffset(intervals);
            Assert.Equal(1, observedMinOffset);
            Assert.Equal(10, observedMaxOffset);
        }
Пример #12
0
        public void GetMinOffset_Nominal()
        {
            const ulong expectedResults   = 3591443256775;
            var         linearFileOffsets = new ulong[1630];

            linearFileOffsets[1629] = expectedResults;

            var idToChunks = new Dictionary <int, Interval[]>
            {
                [6310] = new[] { new Interval(1, 1) }
            };

            var   refSeq          = new ReferenceIndex(ChromosomeUtilities.Chr2, idToChunks, linearFileOffsets);
            ulong observedResults = SearchUtilities.GetMinOffset(refSeq, 26699125);

            Assert.Equal(expectedResults, observedResults);
        }
Пример #13
0
        public void GetMinOffset_MissingFirstBin()
        {
            const ulong expectedResults   = 4351134646660;
            var         linearFileOffsets = new ulong[5353];

            linearFileOffsets[5352] = expectedResults;

            var idToChunks = new Dictionary <int, Interval[]>
            {
                [1254] = new[] { new Interval(1, 1) }
            };

            var   refSeq          = new ReferenceIndex(ChromosomeUtilities.Chr2, idToChunks, linearFileOffsets);
            ulong observedResults = SearchUtilities.GetMinOffset(refSeq, 87687168);

            Assert.Equal(expectedResults, observedResults);
        }
Пример #14
0
        public void GetMinOffset_MissingBin()
        {
            const ulong expectedResults   = 3723191187417;
            var         linearFileOffsets = new ulong[2196];

            linearFileOffsets[2195] = expectedResults;

            var idToChunks = new Dictionary <int, Interval[]>
            {
                [6876] = new[] { new Interval(1, 1) }
            };

            var   refSeq          = new ReferenceIndex(ChromosomeUtilities.Chr2, idToChunks, linearFileOffsets);
            ulong observedResults = SearchUtilities.GetMinOffset(refSeq, 35979265);

            Assert.Equal(expectedResults, observedResults);
        }
Пример #15
0
            protected override void OnStartSearch()
            {
                // note that this will be run from a background thread. Must context switch to the UI thread to manipulate the tree.
                // use ThreadHelper.Generic.BeginInvoke for that

                TreeView      treeView    = modelExplorer.ObjectModelBrowser;
                List <string> searchTexts = SearchUtilities.ExtractSearchTokens(SearchQuery).Select(token => token.ParsedTokenText).ToList();

                if (!searchTexts.Any())
                {
                    ThreadHelper.Generic.BeginInvoke(() =>
                    {
                        // ReSharper disable once UnusedVariable
                        using (WaitCursor w = new WaitCursor())
                        {
                            treeView.SelectedNode = null;
                            treeView.BeginUpdate();
                            modelExplorer.RefreshBrowserView();
                            treeView.CollapseAll();
                            treeView.EndUpdate();
                        }
                    });
                }
                else
                {
                    ThreadHelper.Generic.BeginInvoke(() =>
                    {
                        // ReSharper disable once UnusedVariable
                        using (WaitCursor w = new WaitCursor())
                        {
                            treeView.SelectedNode = null;
                            treeView.BeginUpdate();
                            modelExplorer.RefreshBrowserView();
                            PerformSearch(treeView);
                            treeView.EndUpdate();
                        }
                    });
                }

                SearchResults = (uint)treeView.GetAllNodes().Count(n => n is ExplorerTreeNode explorerNode && explorerNode.RepresentedElement != null);

                // Call to base will report completion
                base.OnStartSearch();
            }
        public void GetSearchResultTest()
        {
            TECSubScope subScope1 = new TECSubScope();

            subScope1.Name = "Test 1";
            TECSubScope subScope2 = new TECSubScope();

            subScope2.Name = "Thingy";

            List <ITECObject> obj = new List <ITECObject>
            {
                subScope1,
                subScope2
            };

            var results = SearchUtilities.GetSearchResult(obj, "test");

            Assert.IsTrue(results.Contains(subScope1));
        }
        /// <summary>
        /// highlight the search term in the supplied result
        /// </summary>
        /// <param name="Result"></param>
        /// <param name="UmbracoProperty"></param>
        /// <param name="Summary"></param>
        /// <returns></returns>
        protected bool LuceneHighlightField(SearchResult Result, UmbracoProperty UmbracoProperty, out string Summary)
        {
            Summary = string.Empty;
            var fieldName = UmbracoProperty.PropertyName;

            if (!string.IsNullOrEmpty(Result.Fields[fieldName]))
            {
                Highlighter highlighter;
                if (HighlighterCache.ContainsKey(fieldName))
                {
                    highlighter = HighlighterCache[fieldName];
                }
                else
                {
                    var searchTerms = SearchUtilities.GetSearchTermsSplit(Parameters.SearchTerm);
                    var luceneQuery = QueryHighlight(UmbracoProperty, searchTerms);
                    var parser      = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, fieldName, _analyzer);
                    // This is needed to make wildcards highlight correctly
                    if (UmbracoProperty.Wildcard)
                    {
                        parser.SetMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
                    }
                    var query = parser.Parse(luceneQuery);
                    query = query.Rewrite(_reader);
                    var scorer = new QueryScorer(query);
                    highlighter = new Highlighter(_formatter, scorer);
                    highlighter.SetTextFragmenter(new SimpleFragmenter(Parameters.SummaryLength));
                    HighlighterCache.Add(fieldName, highlighter);
                }
                using (var sr = new StringReader(Result.Fields[fieldName]))
                {
                    var tokenstream = _analyzer.TokenStream(fieldName, sr);
                    Summary = highlighter.GetBestFragment(tokenstream, Result.Fields[fieldName]);
                    if (!string.IsNullOrEmpty(Summary))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #18
0
        public void AdjustBegin_CorrectNegativeNumbers()
        {
            int observedResult = SearchUtilities.AdjustBegin(0);

            Assert.Equal(0, observedResult);
        }
Пример #19
0
        public void AdjustBegin_Nominal()
        {
            int observedResult = SearchUtilities.AdjustBegin(5);

            Assert.Equal(4, observedResult);
        }
Пример #20
0
            private void PerformSearch(TreeView treeView)
            {
                List <string> searchTexts = SearchUtilities.ExtractSearchTokens(SearchQuery).Select(token => token.ParsedTokenText).ToList();

                // if nothing to search for, everything's a hit
                if (!searchTexts.Any())
                {
                    modelExplorer.ClearSearch();

                    return;
                }

                treeView.BeginUpdate();

                // prune tree to remove non-hits. We don't search the diagram branch. Work is depth-first

                // 1) remove attribute and enum value nodes that aren't matches. This removes attribute group nodes when necessary
                List <ExplorerTreeNode> leafNodes = treeView.GetAllNodes()
                                                    .OfType <ExplorerTreeNode>()
                                                    .Where(n => n.RepresentedElement is ModelAttribute ||
                                                           n.RepresentedElement is ModelEnumValue)
                                                    .ToList();

                foreach (ExplorerTreeNode node in leafNodes.Where(node => searchTexts.All(t => node.Text.IndexOf(t, StringComparison.CurrentCultureIgnoreCase) == -1)))
                {
                    Remove(node);
                }

                // 2) there are cases where a class has no attributes and an enum has no values.
                //    Find those group nodes and remove them, since we couldn't get to them via their child nodes
                List <EFModelRoleGroupTreeNode> emptyChildGroupNodes = treeView.GetAllNodes()
                                                                       .OfType <EFModelRoleGroupTreeNode>()
                                                                       .Where(groupNode => groupNode.Parent is ExplorerTreeNode elementNode &&
                                                                              (elementNode.RepresentedElement is ModelClass ||
                                                                               elementNode.RepresentedElement is ModelEnum) &&
                                                                              groupNode.Nodes.Count == 0)
                                                                       .ToList();

                foreach (EFModelRoleGroupTreeNode emptyChildGroupNode in emptyChildGroupNodes)
                {
                    emptyChildGroupNode.Remove();
                }

                // 3) remove childless class and enum nodes that aren't matches.
                //    Ignore those with children since we can't remove them - their children are matches
                List <ExplorerTreeNode> classNodes = treeView.GetAllNodes()
                                                     .OfType <ExplorerTreeNode>()
                                                     .Where(elementNode => (elementNode.RepresentedElement is ModelClass ||
                                                                            elementNode.RepresentedElement is ModelEnum) &&
                                                            elementNode.Nodes.Count == 0)
                                                     .ToList();

                foreach (ExplorerTreeNode node in classNodes.Where(node => searchTexts.All(t => node.Text.IndexOf(t, StringComparison.CurrentCultureIgnoreCase) == -1)))
                {
                    Remove(node);
                }

                // 4) update the text on all group nodes left in the tree (except for the root)
                List <EFModelRoleGroupTreeNode> groupNodes = treeView.GetAllNodes()
                                                             .OfType <EFModelRoleGroupTreeNode>()
                                                             .Where(n => n != treeView.Nodes[0])
                                                             .ToList();

                foreach (EFModelRoleGroupTreeNode groupNode in groupNodes)
                {
                    groupNode.Text = groupNode.GetNodeText();
                }

                treeView.ExpandAll();

                treeView.EndUpdate();
            }
        private static Expression <Func <Organisation, bool> > GetOrganisationsClause(GridQueryFilter filter)
        {
            var organisations = SearchUtilities.GetIdsFromNameValuePairs(filter.value);

            return(o => organisations.Contains(o.id));
        }
Пример #22
0
        protected void search(List <SearchDocType> itemTypes, string searchText, int?lowerBoundary, int?count,
                              bool?title, bool?description, bool?content, bool?tags, bool?fileContent, bool?forceHasContent,
                              List <Guid> typeIds, List <string> types, bool?showExactItems, bool?suggestNodeTypes,
                              bool?excel, bool?formDetails, Dictionary <string, object> columnNames, ref string responseText)
        {
            //Privacy Check: OK
            if (!paramsContainer.GBView)
            {
                return;
            }

            int initialLowerBoundary = !lowerBoundary.HasValue ? 0 : lowerBoundary.Value;

            if (!count.HasValue)
            {
                count = 10;
            }

            if (excel.HasValue && excel.Value)
            {
                itemTypes = new List <SearchDocType>()
                {
                    SearchDocType.Node
                };
                showExactItems = suggestNodeTypes = false;
                lowerBoundary  = 0;
                count          = 1000000;
            }

            searchText = PublicMethods.convert_numbers_from_local(searchText.Trim());

            //'*' & '?' are not allowed as first character
            if (searchText.Length > 0 && (searchText.IndexOf("*") == 0 || searchText.IndexOf("?") == 0))
            {
                searchText = searchText.Substring(1);
            }

            List <SearchDoc> exactItems = new List <SearchDoc>();
            List <SearchDoc> nodeTypes  = new List <SearchDoc>();

            int totalCount = 0;

            if (!lowerBoundary.HasValue || lowerBoundary == 0)
            {
                string[] terms = searchText.Split(' ');
                int?     _b    = 0;

                if (terms != null && terms.Length == 1 && !string.IsNullOrEmpty(terms[0].Trim()) &&
                    showExactItems.HasValue && showExactItems.Value)
                {
                    exactItems = SearchUtilities.search(paramsContainer.Tenant.Id, itemTypes,
                                                        paramsContainer.CurrentUserID, new List <Guid>(), new List <string>(),
                                                        true, false, false, false, false, false, false, terms[0].Trim(), ref _b, count.Value, false, ref totalCount);
                }

                if (itemTypes.Exists(u => u == SearchDocType.Node) && suggestNodeTypes.HasValue && suggestNodeTypes.Value)
                {
                    List <SearchDocType> sdts = new List <SearchDocType>();
                    sdts.Add(SearchDocType.NodeType);
                    nodeTypes = SearchUtilities.search(paramsContainer.Tenant.Id, sdts,
                                                       paramsContainer.CurrentUserID, new List <Guid>(), new List <string>(),
                                                       true, true, true, false, false, false, false, searchText, ref _b, count.Value, false, ref totalCount);
                }
            }

            totalCount = 0;

            List <SearchDoc> items = SearchUtilities.search(paramsContainer.Tenant.Id,
                                                            itemTypes, paramsContainer.CurrentUserID, typeIds, types, true,
                                                            title.HasValue && title.Value, description.HasValue && description.Value,
                                                            content.HasValue && content.Value, tags.HasValue && tags.Value,
                                                            fileContent.HasValue && fileContent.Value, forceHasContent.HasValue && forceHasContent.Value,
                                                            searchText, ref lowerBoundary, count.Value, highlight: !excel.HasValue || !excel.Value, ref totalCount);

            if (excel.HasValue && excel.Value)
            {
                List <Node> nodes = items.Where(u => (!u.AccessIsDenied.HasValue || !u.AccessIsDenied.Value) &&
                                                u.SearchDocType == SearchDocType.Node && u.TypeID.HasValue).Select(n => new Node()
                {
                    NodeID       = n.ID,
                    Name         = n.Title,
                    NodeTypeID   = n.TypeID,
                    NodeType     = n.Type,
                    AdditionalID = n.AdditionalID
                }).ToList();

                Dictionary <string, string> colsDic = new Dictionary <string, string>();
                columnNames.Keys.ToList().ForEach(k => { colsDic[k] = Base64.decode((string)columnNames[k]); });

                (new CNAPI()
                {
                    paramsContainer = this.paramsContainer
                })
                .export_nodes_to_excel(nodes, colsDic, formDetails.HasValue && formDetails.Value);

                return;
            }

            responseText = "{\"LastItem\":" + lowerBoundary.ToString() +
                           (totalCount == 0 ? string.Empty : ",\"TotalCount\":" + totalCount.ToString()) +
                           ",\"Items\":[" + string.Join(",", items.Select(u => u.toJson(paramsContainer.Tenant.Id, false))) + "]" +
                           ",\"ExactItems\":[" + string.Join(",", exactItems.Select(u => u.toJson(paramsContainer.Tenant.Id, true))) + "]" +
                           ",\"NodeTypes\":[" + string.Join(",", nodeTypes.Select(u => u.toJson(paramsContainer.Tenant.Id, true))) + "]" +
                           ",\"NoMore\":" + (items.Count < count).ToString().ToLower() + "}";

            //Save Log
            if (paramsContainer.CurrentUserID.HasValue && initialLowerBoundary == 0 && !string.IsNullOrEmpty(searchText))
            {
                LogController.save_log(paramsContainer.Tenant.Id, new Log()
                {
                    UserID           = paramsContainer.CurrentUserID.Value,
                    Date             = DateTime.Now,
                    HostAddress      = PublicMethods.get_client_ip(HttpContext.Current),
                    HostName         = PublicMethods.get_client_host_name(HttpContext.Current),
                    Action           = Modules.Log.Action.Search,
                    Info             = "{\"Text\":\"" + (string.IsNullOrEmpty(searchText) ? string.Empty : Base64.encode(searchText)) + "\"}",
                    ModuleIdentifier = ModuleIdentifier.SRCH
                });
            }
            //end of Save Log
        }
Пример #23
0
        /// <summary>
        /// Perform a search using a list of keywords
        /// </summary>
        /// <param name="keywords">List of keywords</param>
        /// <returns>SearchResult object</returns>
        public SearchResult Search(List <string> keywords)
        {
            IService                 serviceProvider;
            string                   searchCriteria;
            SearchEngineQuery        serviceResult;
            List <KeywordInfo>       keywordList       = new List <KeywordInfo>();
            List <SearchEngineQuery> collectionResults = new List <SearchEngineQuery>();
            List <EngineKeyword>     collectionWinners = new List <EngineKeyword>();
            SearchResult             searchResult;
            string                   keyWordWinners;
            string                   totalWinners;
            int seqKeyword = 0;

            //Validating keywords
            if (keywords == null || keywords.Count == 0)
            {
                //Collect validation mesage
                searchResult = new SearchResult
                {
                    Status       = (short)ProcessStatus.Error,
                    ErrorMessage = "Keywords were not found to perform a search"
                };
                return(searchResult);
            }
            if (keywords.FindAll(x => string.IsNullOrWhiteSpace(x)).Count > 0)
            {
                //Collect validation mesage
                searchResult = new SearchResult
                {
                    Status       = (short)ProcessStatus.Error,
                    ErrorMessage = "Any keyword in the list cannot be empty or null"
                };
                return(searchResult);
            }
            try
            {
                //Processing queries for each seach engine
                foreach (string keyword in keywords)
                {
                    seqKeyword++;
                    keywordList.Add(
                        new KeywordInfo {
                        Id = seqKeyword, Keyword = keyword
                    }
                        );
                    searchCriteria = SearchUtilities.RemoveExtraBlankSpaces(keyword);
                    foreach (SearchEngineInfo searchEngine in _searchEngines)
                    {
                        serviceProvider         = SearchFactory.GetService(searchEngine.Id);
                        serviceResult           = serviceProvider.Search(searchCriteria).GetAwaiter().GetResult();
                        serviceResult.KeywordId = seqKeyword;
                        serviceResult.Keyword   = keyword;
                        collectionResults.Add(serviceResult);
                    }
                }
                //Get winners for each search engine
                foreach (var item in _searchEngines)
                {
                    keyWordWinners = SearchUtilities.GetWinners(collectionResults, item.Name);

                    collectionWinners.Add(new EngineKeyword
                    {
                        SearchEngine   = item.Name,
                        KeywordWinners = keyWordWinners
                    });
                }
                //Get total winners
                totalWinners = SearchUtilities.GetTotalWinners(collectionResults, keywordList);
                //Build output with search results and winners
                searchResult = new SearchResult
                {
                    Status = (short)ProcessStatus.Success,
                    SearchEngineResults = collectionResults,
                    KeywordResults      = collectionWinners,
                    TotalWinners        = totalWinners
                };
            }
            catch (Exception ex)
            {
                //Collect error information
                searchResult = new SearchResult
                {
                    Status       = (short)ProcessStatus.Error,
                    ErrorMessage = ex.Message
                };
            }
            return(searchResult);
        }