Esempio n. 1
0
 private static void ExcludeUnwantedFields(SearchRequest <ElasticArchiveRecord> searchRequest)
 {
     // Exclude content from primarydata.
     searchRequest.Source = new SourceFilter {
         Excludes = Infer.Fields("all", "primaryData.items.content")
     };
 }
        private static Fields GetQueryFields()
        {
            var fieldWeights = new List <string>();
            var properties   = new List <string>();

            foreach (var field in ServiceLocator.Current.GetInstance <IDynamicDataRepository <WeightSetting> >().ReadAll())
            {
                var elasticPropertyName = field.Property.ToElasticPropertyName();

                fieldWeights.Add($"{elasticPropertyName}.{IndexSettingsFactory.Names.Analyzers.Shorthand.Language}^{field.Weight:0.#}");
                fieldWeights.Add($"{elasticPropertyName}.{IndexSettingsFactory.Names.Analyzers.Shorthand.Ngram}^{field.Weight / 3:0.#}");

                properties.Add(elasticPropertyName);
            }

            foreach (var property in ServiceLocator.Current.GetInstance <ElasticEpiDocument>().GetLanguageAnalyzableProperties())
            {
                var elasticPropertyName = property.ToElasticPropertyName();

                if (properties.Contains(elasticPropertyName))
                {
                    continue;
                }

                // Add default weighting if not set by admin through Epi DDS
                fieldWeights.Add($"{elasticPropertyName}.{IndexSettingsFactory.Names.Analyzers.Shorthand.Language}^1.0");
                fieldWeights.Add($"{elasticPropertyName}.{IndexSettingsFactory.Names.Analyzers.Shorthand.Ngram}^0.3");
            }

            return(Infer.Fields(fieldWeights.ToArray()));
        }
		protected PutRoleRequest CreateInitializer(string role) => new PutRoleRequest(CreateRoleName(role))
		{
			Cluster = new[] { "all" },
			Indices = new List<IIndicesPrivileges>
			{
				new IndicesPrivileges
				{
					Fields = Infer.Fields<Project>(p=>p.Name).And<Project>(p=>p.Description),
					Names = Infer.Indices<Project>(),
					Privileges = new [] { "all" },
					Query = new MatchAllQuery()
				}
			}
		};
        public SearchResult <Worktask> Search(string username, string query, int page, int pageSize)
        {
            int[] boardIdList = KanbanService.GetInstance().UserBoardList(username).Select(b => b.Id).ToArray();
            var   search      = new SearchRequest
            {
                Query = new MultiMatchQuery
                {
                    Query  = query,
                    Fields = Infer.Fields("attachments.attachment_content", "task_title", "task_description", "task_identify")
                },

                Highlight = new Highlight
                {
                    PreTags  = new[] { "<sr>" },
                    PostTags = new[] { "</sr>" },
                    Fields   = new Dictionary <Field, IHighlightField>
                    {
                        { "*", new HighlightField {
                          } }
                    }
                }
            };

            var result     = client.Search <Worktask>(search);
            var highlights = result.Hits.Select(h => new SearchResultItem <Worktask>(h.Highlights, h.Source)).ToList();

            return(new SearchResult <Worktask>
            {
                Total = (int)result.Total,
                Page = page,
                Results = result.Documents.Where(d => boardIdList.Any(i => i == d.BoardID)).ToList(),
                Highlights = highlights.Where(d => boardIdList.Any(i => i == d.Source.BoardID)),
                ElapsedMilliseconds = result.Took,
                IsValid = result.IsValid
            });
        }