コード例 #1
0
        public ISearchResponse <ScientificPaperDocument> Search(ScientificPaperSearchRequest request)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            string searchStringQuery = GetQueryString(request);

            if (searchStringQuery.Equals(string.Empty))
            {
                return(new SearchResponse <ScientificPaperDocument>());
            }

            return(Search <ScientificPaperDocument>(s => s
                                                    .Index(DEFAULT_INDEX)
                                                    .Query(q => q
                                                           .QueryString(qs => qs
                                                                        .Query(searchStringQuery)))
                                                    .Highlight(h => h.PreTags(PRE_TAG_HIGHLIGHER).PostTags(POST_TAG_HIGHLIGHER).Encoder(HighlighterEncoder.Html)
                                                               .Fields(
                                                                   f => f.Field(MAGAZINE_TITLE_FIELD),
                                                                   f => f.Field(TITLE_FIELD),
                                                                   f => f.Field(AUTHOR_FIRSTNAME_FIELD),
                                                                   f => f.Field(AUTHOR_LASTNAME_FIELD),
                                                                   f => f.Field(KEYWORDS_FIELD),
                                                                   f => f.Field(SCIENTIFIC_FIELDS_FIELD),
                                                                   f => f.Field(CONTENT_FIELD)))));
        }
コード例 #2
0
        public string SearchScientificPaper(ScientificPaperSearchRequest request)
        {
            ISearchResponse <ScientificPaperDocument> response;

            if (request.MoreLikeThisEnabled)
            {
                response = client.MoreLikeThis(request);
            }
            else
            {
                response = client.Search(request);
            }

            return(JsonConvert.SerializeObject(response.Hits.ToList(), Formatting.Indented));
        }
コード例 #3
0
        private string GetQueryString(ScientificPaperSearchRequest request)
        {
            string magazineTitleQuery    = CreateQuery(MAGAZINE_TITLE_FIELD, request.MagazineTitle, request.Operation);
            string titleQuery            = CreateQuery(TITLE_FIELD, request.Title, request.Operation);
            string authorFirstnameQuery  = CreateQuery(AUTHOR_FIRSTNAME_FIELD, request.AuthorFirstname, request.Operation);
            string authorLastnameQuery   = CreateQuery(AUTHOR_LASTNAME_FIELD, request.AuthorLastname, request.Operation);
            string keywordsQuery         = CreateQuery(KEYWORDS_FIELD, request.Keyword, request.Operation);
            string scientificFieldsQuery = CreateQuery(SCIENTIFIC_FIELDS_FIELD, request.ScientificField, request.Operation);
            string attachmentQuery       = CreateQuery(CONTENT_FIELD, request.Content, request.Operation);

            string searchStringQuery = string.Format("{0} {1} {2} {3} {4} {5} {6}",
                                                     magazineTitleQuery, titleQuery, authorFirstnameQuery, authorLastnameQuery, keywordsQuery, scientificFieldsQuery, attachmentQuery).Trim();

            if (searchStringQuery.Length < 1)
            {
                return(string.Empty);
            }

            // searchString can't have operator at the end: remove last operator and return searchString
            return(searchStringQuery.Substring(0, searchStringQuery.Length - request.Operation.Length).Trim());
        }
コード例 #4
0
        public ISearchResponse <ScientificPaperDocument> MoreLikeThis(ScientificPaperSearchRequest request)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            return(Search <ScientificPaperDocument>(s => s
                                                    .Index(DEFAULT_INDEX)
                                                    .Query(q => q
                                                           .MoreLikeThis(mlt => mlt
                                                                         .Fields(f => f
                                                                                 .Field(MAGAZINE_TITLE_FIELD)
                                                                                 .Field(TITLE_FIELD)
                                                                                 .Field(AUTHOR_FIRSTNAME_FIELD)
                                                                                 .Field(AUTHOR_LASTNAME_FIELD)
                                                                                 .Field(KEYWORDS_FIELD)
                                                                                 .Field(SCIENTIFIC_FIELDS_FIELD)
                                                                                 .Field(CONTENT_FIELD))
                                                                         .Like(l => l
                                                                               .Text(request.MoreLikeThisQuery))
                                                                         .MinDocumentFrequency(1)
                                                                         .MinTermFrequency(1)))
                                                    .Highlight(h => h.PreTags(PRE_TAG_HIGHLIGHER).PostTags(POST_TAG_HIGHLIGHER).Encoder(HighlighterEncoder.Html)
                                                               .Fields(
                                                                   f => f.Field(MAGAZINE_TITLE_FIELD)
                                                                   .HighlightQuery(q => q
                                                                                   .Match(m => m
                                                                                          .Field(p => p.ScientificPaper.MagazineTitle)
                                                                                          .Query(request.MoreLikeThisQuery)
                                                                                          )
                                                                                   ),
                                                                   f => f.Field(TITLE_FIELD)
                                                                   .HighlightQuery(q => q
                                                                                   .Match(m => m
                                                                                          .Field(p => p.ScientificPaper.Title)
                                                                                          .Query(request.MoreLikeThisQuery)
                                                                                          )
                                                                                   ),
                                                                   f => f.Field(AUTHOR_FIRSTNAME_FIELD)
                                                                   .HighlightQuery(q => q
                                                                                   .Match(m => m
                                                                                          .Field(p => p.ScientificPaper.Authors.First().Firstname)
                                                                                          .Query(request.MoreLikeThisQuery)
                                                                                          )
                                                                                   ),
                                                                   f => f.Field(AUTHOR_LASTNAME_FIELD)
                                                                   .HighlightQuery(q => q
                                                                                   .Match(m => m
                                                                                          .Field(p => p.ScientificPaper.Authors.First().Lastname)
                                                                                          .Query(request.MoreLikeThisQuery)
                                                                                          )
                                                                                   ),
                                                                   f => f.Field(KEYWORDS_FIELD)
                                                                   .HighlightQuery(q => q
                                                                                   .Match(m => m
                                                                                          .Field(p => p.ScientificPaper.Keywords.First().Title)
                                                                                          .Query(request.MoreLikeThisQuery)
                                                                                          )
                                                                                   ),
                                                                   f => f.Field(SCIENTIFIC_FIELDS_FIELD)
                                                                   .HighlightQuery(q => q
                                                                                   .Match(m => m
                                                                                          .Field(p => p.ScientificPaper.ScientificFields.First().Title)
                                                                                          .Query(request.MoreLikeThisQuery)
                                                                                          )
                                                                                   ),
                                                                   f => f.Field(CONTENT_FIELD)
                                                                   .HighlightQuery(q => q
                                                                                   .Match(m => m
                                                                                          .Field(p => p.Attachment.Content)
                                                                                          .Query(request.MoreLikeThisQuery)))))));
        }