Custom Search Index Content Always Returns Lower Case Content

Suman Layek asked on November 8, 2016 16:39

Hello, Don't know why this Custom Search Index Content Always Returning Lower Case Content On Search Result. Is there anyone who can help me solve the issue and let me know why this is happening

Below is the CustomIndex Class

public class KidsHealthArticlesIndex : ICustomSearchIndex
    public void Rebuild(SearchIndexInfo srchInfo)
        if (srchInfo != null)
            // Gets an index writer object for the current index
            IIndexWriter iw = srchInfo.Provider.GetWriter(true);

            if (iw != null)
                   SearchIndexSettingsInfo sisi = srchInfo.IndexSettings.Items[SearchHelper.CUSTOM_INDEX_DATA];
                    srchInfo.IndexDisplayName = srchInfo.IndexDisplayName.ToUpper();

                    // Gets the search path from the Index data field
                    string language = Convert.ToString(sisi.GetValue("CustomData"));
                    DataSet dsArticles = new DataQuery("NCH.KidsHealthTransformations.GetCategoryArticles").Distinct(true).Columns("ArticleTitle As Title", "ArticleBodyPageHtml As PageHtml", "ArticleAliasName As AliasName", "SectionDisplayName", "SectionAliasName", "IsArticlePage", "Language").WhereEquals("IsArticlePage", true).And().WhereEquals("Language", language).Result;
                    DataSet dsCategories = new DataQuery("NCH.KidsHealthTransformations.GetCategoryArticles").Distinct(true).Columns("CategoryDisplayName As Title", "CategoryBodyPageHtml As PageHtml", "CategoryAliasName As AliasName", "SectionDisplayName", "SectionAliasName", "IsArticlePage", "Language").WhereEquals("IsArticlePage", false).And().WhereEquals("Language", language).Result;
                    DataTable categoryArticlePages = new DataTable();
                    if (!DataHelper.DataSourceIsEmpty(dsArticles))
                        categoryArticlePages = dsArticles.Tables[0];
                        if (!DataHelper.DataSourceIsEmpty(dsCategories))
                            var dt1 = dsArticles.Tables[0];
                            var dt2 = dsCategories.Tables[0];
                            categoryArticlePages = dt1.AsEnumerable().Union(dt2.AsEnumerable()).OrderBy(d => d.Field<string>("Title")).CopyToDataTable();
                    if (categoryArticlePages.Rows.Count > 0)
                        foreach (DataRow row in categoryArticlePages.Rows)

                            // Creates a new Lucene.Net search document for the current text file
                            SearchDocumentParameters documentParameters = new SearchDocumentParameters()
                                Index = srchInfo,
                                Type = SearchHelper.CUSTOM_SEARCH_INDEX,
                                Id = Guid.NewGuid().ToString(),
                                Created = DateTime.Now
                            ISearchDocument doc = SearchHelper.CreateDocument(documentParameters);

                            // Adds a content field. This field is processed when the search looks for matching results.

                            doc.AddGeneralField(SearchFieldsConstants.CONTENT, Convert.ToString(row["Title"]), false, false); // SearchHelper.StoreContentField, true);

                            // Adds a title field. The value of this field is used for the search result title.
                            doc.AddGeneralField(SearchFieldsConstants.CUSTOM_TITLE, Convert.ToString(row["Title"]), false, false);

                            // Adds a content field. The value of this field is used for the search result excerpt.
                            doc.AddGeneralField(SearchFieldsConstants.CUSTOM_CONTENT, HTMLHelper.StripTags(Convert.ToString(row["PageHtml"])), false, false);

                            // Adds a date field. The value of this field is used for the date in the search results.
                            doc.AddGeneralField(SearchFieldsConstants.CUSTOM_DATE, DateTime.Now, true, false);

                            // Adds a url field. The value of this field is used for link urls in the search results.
                            doc.AddGeneralField(SearchFieldsConstants.CUSTOM_URL, "/health-information-library/" + Convert.ToString(row["Language"]) + "/" + Convert.ToString(row["SectionAliasName"]) + "/" + (Convert.ToBoolean(row["IsArticlePage"]) == true ? "article" : "category") + "/" + Convert.ToString(row["AliasName"]), true, false);

                            // Adds a title field. The value of this field is used for the search result title.
                            doc.AddGeneralField("ClassName", "KidsHealth", true, false);

                            // Adds an image field. The value of this field is used for the images in the search results.
                            // Commented out, since the image file does not exist by default
                            // doc.AddGeneralField(SearchFieldsConstants.CUSTOM_IMAGEURL, "textfile.jpg", true, false);

                            // Adds the document to the index

                        // Flushes the index buffer

                        // Optimizes the index
                // Logs any potential exceptions
                catch (Exception ex)
                    EventLogProvider.LogException("KidsHealthArticlesIndex", "Rebuild", ex);

                // Always close the index writer

Recent Answers

Zachary Perry answered on November 8, 2016 17:23 (last edited on November 8, 2016 17:26)

try to use SearchHelper.AddGeneralField(doc, stringname, value, store, tokenize, tolower) in addition to doc.AddGeneralField(). It allows you to pass in a bool on if the value should be converted to all lowercase. This would create custom fields that you would have to use in your results transformation.

0 votesVote for this answer Mark as a Correct answer

Anton Grekhovodov answered on November 8, 2016 17:42

The same question here index values no lowercase

3 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.