【问题标题】:Custom index of Kentico searching in media library is not adding the index to the search媒体库中 Kentico 搜索的自定义索引未将索引添加到搜索中
【发布时间】:2019-05-05 06:04:20
【问题描述】:

我正在尝试添加自定义索引以进行搜索,但该文件未添加到结果中。 这是我的重建方法代码,正在正确的媒体库中查找文档,但结果中没有检索到这些文档。

try
                {
                    MediaLibraryInfo library = MediaLibraryInfoProvider.GetMediaLibraryInfo("Documents", SiteContext.CurrentSiteName);

                    if (library != null)
                    {

                        var mediaFiles = MediaFileInfoProvider.GetMediaFiles().WhereEquals("FileLibraryID", library.LibraryID);// all files extension

                        List<string> files = new List<string>();

                        foreach (MediaFileInfo mediafile in mediaFiles)
                        {

                            SearchDocumentParameters documentParameters = new SearchDocumentParameters()
                            {
                                Index = srchInfo,
                                Type = SearchHelper.CUSTOM_SEARCH_INDEX,
                                Id = Guid.NewGuid().ToString(),
                                Created = mediafile.FileCreatedWhen
                            };
                            ILuceneSearchDocument doc = LuceneSearchDocumentHelper.ToLuceneSearchDocument(SearchHelper.CreateDocument(documentParameters));
                            doc.AddGeneralField(SearchFieldsConstants.CUSTOM_TITLE, mediafile.FileTitle, true, true);
                            doc.AddGeneralField("NAME", mediafile.FileName, true, true);
                            doc.AddGeneralField("DESCRIPTION", mediafile.FileDescription, true, true);

                            iw.AddDocument(doc);

                        }

                        iw.Flush();
                        iw.Optimize();
                    }
                }

                catch (Exception ex)
                {
                    EventLogProvider.LogException("CustomTextFileIndex", "Rebuild", ex);
                }

                // Always close the index writer
                finally
                {
                    iw.Close();
                }

【问题讨论】:

    标签: search indexing kentico media-library


    【解决方案1】:

    带有自定义名称和描述的 doc.AddGeneralField 行不适用于 Kentico 的默认列命名约定,您应该改用以下内容:

    doc.AddGeneralField(SearchFieldsConstants.CUSTOM_TITLE, mediafile.FileName, true, true);
    doc.AddGeneralField(SearchFieldsConstants.CUSTOM_CONTENT, mediafile.FileDescription, true, true);
    

    Kentico 中的默认搜索机制不会为其查询使用任何自定义列名。您必须为该功能创建自定义 Lucene 查询。如果您已将 CUSTOM_TITLE 或 CUSTOM_CONTENT 字段用于其他内容,则只需将内容添加到同一字段,例如:

    doc.AddGeneralField(SearchFieldsConstants.CUSTOM_TITLE, $"{mediafile.FileTitle} {mediafile.FileName}", true, true);
    

    您可以使用名为 Luke 的工具验证 Lucene 索引是否包含记录,我使用 3.5 版(4+ 不适用于 Kentico 索引) https://code.google.com/archive/p/luke/downloads

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多