예제 #1
0
        private SearchResult GetSearchResultFromLuceneResult(LuceneResult luceneResult)
        {
            var result = new SearchResult();
            var doc    = luceneResult.Document;

            result.DisplayScore = luceneResult.DisplayScore;
            result.Score        = luceneResult.Score;

            // set culture code of result
            result.CultureCode = string.Empty;
            var localeField = luceneResult.Document.GetField(Constants.LocaleTag);

            if (localeField != null)
            {
                int id;
                if (int.TryParse(localeField.StringValue, out id) && id >= 0)
                {
                    result.CultureCode = LocaleController.Instance.GetLocale(id).Code;
                }
                else
                {
                    result.CultureCode = Null.NullString;
                }
            }

            FillTagsValues(doc, result);
            result.Snippet = GetSnippet(result, luceneResult);
            return(result);
        }
예제 #2
0
        private static string GetSnippet(SearchResult searchResult, LuceneResult luceneResult)
        {
            var sb = new StringBuilder();

            if (!string.IsNullOrEmpty(luceneResult.TitleSnippet))
            {
                sb.Append(luceneResult.TitleSnippet + "...");
            }

            if (!string.IsNullOrEmpty(luceneResult.DescriptionSnippet))
            {
                sb.Append(luceneResult.DescriptionSnippet + "...");
            }

            if (!string.IsNullOrEmpty(luceneResult.TagSnippet))
            {
                sb.Append(luceneResult.TagSnippet + "...");
            }

            if (!string.IsNullOrEmpty(luceneResult.BodySnippet))
            {
                sb.Append(luceneResult.BodySnippet + "...");
            }

            if (!string.IsNullOrEmpty(luceneResult.AuthorSnippet))
            {
                sb.Append(luceneResult.AuthorSnippet + "...");
            }

            if (!string.IsNullOrEmpty(luceneResult.ContentSnippet))
            {
                sb.Append(luceneResult.ContentSnippet + "...");
            }

            var snippet = sb.ToString();

            if (string.IsNullOrEmpty(snippet))
            {
                snippet = searchResult.Title;
            }

            return(snippet);
        }
예제 #3
0
        public ISonesFulltextResult Query(string myQuery)
        {
            var result = _LuceneIndex.GetEntries(_MaxResultsFirst, myQuery);

            if (result == null)
            {
                throw new ArgumentException("Query string is not valid.");
            }

            if (result.TotalHits > _MaxResultsFirst)
            {
                result = _LuceneIndex.GetEntries(result.TotalHits, myQuery);
            }

            var lucene_result =  new LuceneResult(result);

            return lucene_result;
        }