Exemple #1
0
        public static string GetSpecificQueriesForDataset(DataSet ds, string mappingProperty, string query)
        {
            var props   = ds.GetMappingList(mappingProperty).ToArray();
            var qSearch = SearchDataQuery(props, query);

            return(qSearch);
        }
Exemple #2
0
        public static string GetSpecificQueriesForDataset(DataSet ds, string mappingProperty, string query, bool addKeyword, string attrNameModif = "")
        {
            var props = ds.GetMappingList(mappingProperty, attrNameModif).ToArray();

            if (addKeyword)
            {
                for (int i = 0; i < props.Length; i++)
                {
                    props[i] += ".keyword";
                }
            }
            var qSearch = SearchDataQuery(props, query);

            return(qSearch);
        }
Exemple #3
0
        public static ISearchResponse <object> _searchData(DataSet ds, string queryString, int page, int pageSize, string sort = null, bool excludeBigProperties = true)
        {
            SortDescriptor <object> sortD = new SortDescriptor <object>();

            if (sort == "0")
            {
                sort = null;
            }

            if (!string.IsNullOrEmpty(sort))
            {
                if (sort.EndsWith(DataSearchResult.OrderDesc) || sort.ToLower().EndsWith(DataSearchResult.OrderDescUrl))
                {
                    sort  = sort.Replace(DataSearchResult.OrderDesc, "").Replace(DataSearchResult.OrderDescUrl, "").Trim();
                    sortD = sortD.Field(sort, SortOrder.Descending);
                }
                else
                {
                    sort  = sort.Replace(DataSearchResult.OrderAsc, "").Replace(DataSearchResult.OrderAscUrl, "").Trim();
                    sortD = sortD.Field(sort, SortOrder.Ascending);
                }
            }


            Nest.ElasticClient client = Lib.ES.Manager.GetESClient(ds.DatasetId, idxType: ES.Manager.IndexType.DataSource);

            QueryContainer qc = GetSimpleQuery(ds, queryString);

            //QueryContainer qc = null;
            //if (queryString == null)
            //    qc = new QueryContainerDescriptor<object>().MatchNone();
            //else if (string.IsNullOrEmpty(queryString))
            //    qc = new QueryContainerDescriptor<object>().MatchAll();
            //else
            //{
            //    qc = new QueryContainerDescriptor<object>()
            //        .QueryString(qs => qs
            //            .Query(queryString)
            //            .DefaultOperator(Operator.And)
            //        );
            //}

            page = page - 1;
            if (page < 0)
            {
                page = 0;
            }
            if (page * pageSize > Lib.ES.SearchTools.MaxResultWindow)
            {
                page = (Lib.ES.SearchTools.MaxResultWindow / pageSize) - 1;
            }

            //exclude big properties from result
            var maps = excludeBigProperties ? ds.GetMappingList("DocumentPlainText").ToArray() : new string[] { };


            var res = client
                      .Search <object>(s => s
                                       .Type("data")
                                       .Size(pageSize)
                                       .Source(ss => ss.Excludes(ex => ex.Fields(maps)))
                                       .From(page * pageSize)
                                       .Query(q => qc)
                                       .Sort(ss => sortD)
                                       );

            return(res);
        }
Exemple #4
0
        public static ISearchResponse <object> _searchData(DataSet ds, string queryString, int page, int pageSize, string sort = null,
                                                           bool excludeBigProperties = true, bool withHighlighting = false, bool exactNumOfResults = false)
        {
            SortDescriptor <object> sortD = new SortDescriptor <object>();

            if (sort == "0")
            {
                sort = null;
            }

            if (!string.IsNullOrEmpty(sort))
            {
                if (sort.EndsWith(DataSearchResult.OrderDesc) || sort.ToLower().EndsWith(DataSearchResult.OrderDescUrl))
                {
                    sort  = sort.Replace(DataSearchResult.OrderDesc, "").Replace(DataSearchResult.OrderDescUrl, "").Trim();
                    sortD = sortD.Field(sort, SortOrder.Descending);
                }
                else
                {
                    sort  = sort.Replace(DataSearchResult.OrderAsc, "").Replace(DataSearchResult.OrderAscUrl, "").Trim();
                    sortD = sortD.Field(sort, SortOrder.Ascending);
                }
            }


            Nest.ElasticClient client = Lib.ES.Manager.GetESClient(ds.DatasetId, idxType: ES.Manager.IndexType.DataSource);

            QueryContainer qc = GetSimpleQuery(ds, queryString);

            //QueryContainer qc = null;
            //if (queryString == null)
            //    qc = new QueryContainerDescriptor<object>().MatchNone();
            //else if (string.IsNullOrEmpty(queryString))
            //    qc = new QueryContainerDescriptor<object>().MatchAll();
            //else
            //{
            //    qc = new QueryContainerDescriptor<object>()
            //        .QueryString(qs => qs
            //            .Query(queryString)
            //            .DefaultOperator(Operator.And)
            //        );
            //}

            page = page - 1;
            if (page < 0)
            {
                page = 0;
            }
            if (page * pageSize > Lib.Data.Smlouva.Search.MaxResultWindow)
            {
                page = (Lib.Data.Smlouva.Search.MaxResultWindow / pageSize) - 1;
            }

            //exclude big properties from result
            var maps = excludeBigProperties ? ds.GetMappingList("DocumentPlainText").ToArray() : new string[] { };



            var res = client
                      .Search <object>(s => s
                                       .Size(pageSize)
                                       .Source(ss => ss.Excludes(ex => ex.Fields(maps)))
                                       .From(page * pageSize)
                                       .Query(q => qc)
                                       .Sort(ss => sortD)
                                       .Highlight(h => Lib.Searching.Tools.GetHighlight <Object>(withHighlighting))
                                       .TrackTotalHits(exactNumOfResults ? true : (bool?)null)
                                       );

            //fix Highlighting for large texts
            if (withHighlighting &&
                res.Shards != null &&
                res.Shards.Failed > 0)    //if some error, do it again without highlighting
            {
                res = client
                      .Search <object>(s => s
                                       .Size(pageSize)
                                       .Source(ss => ss.Excludes(ex => ex.Fields(maps)))
                                       .From(page * pageSize)
                                       .Query(q => qc)
                                       .Sort(ss => sortD)
                                       .Highlight(h => Lib.Searching.Tools.GetHighlight <Object>(false))
                                       .TrackTotalHits(exactNumOfResults ? true : (bool?)null)
                                       );
            }

            Audit.Add(Audit.Operations.Search, "", "", "Dataset." + ds.DatasetId, res.IsValid ? "valid" : "invalid", queryString, null);

            return(res);
        }