public void testSearchByANDFoundFromPortal()
            {
                ElasticDocument document = new ElasticDocument();
                document.Search.Owner = "adm_phillipe";
                document.Search.Name = "Sound Device";

                SearchCriteria criteria = new SearchCriteria(SHOULD, MATCH);
                var results = myEngine.Search(document, criteria);

                Assert.AreEqual(1, results.Count());
            }
            public void testSearchByANDBadFromPortal()
            {
                ElasticDocument document = new ElasticDocument();
                document.Search.Owner = "garcia";
                document.Search.Name = "accxount";

                SearchCriteria criteria = new SearchCriteria(SHOULD, MATCH);
                var results = myEngine.Search(document, criteria);

                Assert.AreEqual(0, results.Count());
            }
            public void testSearchByNameHitWeirdFromPortal()
            {
                ElasticDocument document = new ElasticDocument();
                document.Search.Owner = "Dagmar  garccia";
                document.Search.Name = "juan";

                SearchCriteria criteria = new SearchCriteria(SHOULD, MATCH);
                var results = myEngine.Search(document, criteria);

                Assert.AreEqual(0, results.Count());
            }
            public void testSearchByNameFromPortal()
            {
                ElasticDocument document = new ElasticDocument();
                document.Search.Name = "Group Grouping Subreport";
                document.Search.Owner = "CITRITE\\adm_phillipe";

                SearchCriteria criteria = new SearchCriteria(SHOULD, MATCH);
                var results = myEngine.Search(document, criteria);
                
                foreach(var e in results)
                    Debug.WriteLine(e.ToString());

                Assert.AreEqual(10993, results.Count());
            }
        public void testSearchByNameOwnerMustNoResult()
        {
            ElasticDocument document = new ElasticDocument();
            document.Search.Name = "Contract Affiliate";
            document.Search.Owner = "adm_phillipe";

            SearchCriteria criteria = new SearchCriteria(MUST, MATCH);
            var results = myEngine.Search(document, criteria);

            Assert.AreEqual(0, results.Count());

        }  
        public void testSearchByNameSM()
        {                        
            ElasticDocument document = new ElasticDocument();
            document.Search.Name = "Worldwide Touchpoints";

            SearchCriteria criteria = new SearchCriteria(SHOULD, MATCH);
            var results = myEngine.Search(document, criteria);

            Assert.AreEqual(2, results.Count());
            
        }
예제 #7
0
        public ElasticsearchDynamicValue[] Search(ElasticDocument objectToSearch, SearchCriteria p_criteria)
        //public IEnumerable<ElasticDocument> Search(ElasticDocument objectToSearch)
        {
            ElasticsearchDynamicValue[] response = null;
            QueryContainer queryContainer = new QueryContainer();

           /*
            var queryMatchName = new MatchQueryDescriptor<ElasticDocument>().OnField("_search.name").Query(objectToSearch.Search.Name);
            var queryMatchDescription = new MatchQueryDescriptor<ElasticDocument>().OnField("_search.description").Query(objectToSearch.Search.Description);
            var queryMatchOwner = new MatchQueryDescriptor<ElasticDocument>().OnField("_search.owner").Query(objectToSearch.Search.Owner);

            var queryTermName = new TermQueryDescriptor<ElasticDocument>().OnField("_search.name").Value(objectToSearch.Search.Name);
            var queryTermDescription = new TermQueryDescriptor<ElasticDocument>().OnField("_search.description").Value(objectToSearch.Search.Description);
            var queryTermOwner = new TermQueryDescriptor<ElasticDocument>().OnField("_search.owner").Value(objectToSearch.Search.Owner);
            */

            if (p_criteria.Condition.Equals(SHOULD) && p_criteria.QueryType.Equals(MATCH))
                queryContainer = new QueryDescriptor<ElasticDocument>().Bool(b => b.
                            Should(s => s.Match(m => m.OnField("_search.name").Query(objectToSearch.Search.Name)) ||
                                        s.Match(m => m.OnField("_search.description").Query(objectToSearch.Search.Description)) ||
                                        s.Match(m => m.OnField("_search.owner").Query(objectToSearch.Search.Owner))));

            if (p_criteria.Condition.Equals(MUST) && p_criteria.QueryType.Equals(MATCH))
                queryContainer = new QueryDescriptor<ElasticDocument>().Bool(b => b.
                            Must(s => s.Match(m => m.OnField("_search.name").Query(objectToSearch.Search.Name)) &&
                                      s.Match(m => m.OnField("_search.description").Query(objectToSearch.Search.Description)) &&
                                      s.Match(m => m.OnField("_search.owner").Query(objectToSearch.Search.Owner))));

            if (p_criteria.Condition.Equals(SHOULD) && p_criteria.QueryType.Equals(TERM))
                queryContainer = new QueryDescriptor<ElasticDocument>().Bool(b => b.
                        Should(s => s.Term(m => m.OnField("_search.name").Value(objectToSearch.Search.Name)) ||
                                    s.Term(m => m.OnField("_search.description").Value(objectToSearch.Search.Description)) ||
                                    s.Term(m => m.OnField("_search.owner").Value(objectToSearch.Search.Owner))));

            if (p_criteria.Condition.Equals(MUST) && p_criteria.QueryType.Equals(TERM))
                queryContainer = new QueryDescriptor<ElasticDocument>().Bool(b => b.
                            Must(s => s.Term(m => m.OnField("_search.name").Value(objectToSearch.Search.Name)) &&
                                      s.Term(m => m.OnField("_search.description").Value(objectToSearch.Search.Description)) &&
                                      s.Term(m => m.OnField("_search.owner").Value(objectToSearch.Search.Owner))));
            
            var searchDescriptor = new SearchDescriptor<ElasticDocument>().
                Query(queryContainer);

            var request = clientElasticNest.Serializer.Serialize(searchDescriptor);

            var results = clientElasticNest.Raw.Search(request);

            int total_hits = (int)results.Response[HITS][TOTAL_HITS];
            ElasticsearchDynamicValue hits = results.Response[HITS][HITS];

            if (total_hits > 0)
                response = new ElasticsearchDynamicValue[total_hits];
            else
                response = new ElasticsearchDynamicValue[0];

            for (int i = 0; i < total_hits; i++)
            {
                response[i] = hits[i];
            }

            return response;
            
        }