Can I search/index a custom datasource in Orchard via Lucene?

回眸只為那壹抹淺笑 提交于 2019-12-04 07:23:51
Keith

For those searching for a similar answer, the following solution is what I settled on. There is no easy mechanism I could find to interact with a separate DAL and perform the Lucene indexing.

  1. Create the Orchard Module
  2. Create new Content Part/Type via aMigration
  3. Use Orchard Command infrastructure to import data from your secondary database
  4. Use the OnIndexing event in the Content Part handler to allow Lucene to index your datasource.
  5. Create a lookup property (I called mine ConcreateProperty) that is populated through a Service I created in the module to interact with the secondary DAL in the OnLoaded event.

My final Handler looked like this:

public class HomePartHandler : ContentHandler {
    public HomePartHandler(IRepository<HomePartRecord> repository, IHomeSearchMLSService homeSearchService) {
        Filters.Add(StorageFilter.For(repository));
        OnLoaded<HomePart>((ctx, part) =>
        {
            part.ConcreteProperty = homeSearchService.GetByMlsNumber(part.MlsId) ?? new PropertyDetail();
        });
        OnIndexing<HomePart>((context, homePart) => context.DocumentIndex
         .Add("home_StreetFullName", homePart.Record.StreetFullName).RemoveTags().Analyze().Store()
         .Add("home_City", homePart.Record.City).RemoveTags().Analyze().Store()
         .Add("home_State", homePart.Record.State).RemoveTags().Analyze().Store()
         .Add("home_Zip", homePart.Record.Zip).RemoveTags().Analyze().Store()
         .Add("home_Subdivision", homePart.Record.Subdivision).RemoveTags().Analyze().Store()
         .Add("home_Beds", homePart.Record.Beds).RemoveTags().Analyze().Store()
         .Add("home_Baths", homePart.Record.Baths).RemoveTags().Analyze().Store()
         .Add("home_SquareFoot", homePart.Record.SquareFoot).RemoveTags().Analyze().Store()
         .Add("home_PropertyType", homePart.Record.PropertyType).RemoveTags().Analyze().Store()
         .Add("home_ListPrice", homePart.Record.ListPrice).RemoveTags().Analyze().Store()
         .Add("home_MlsId", homePart.Record.MlsId).RemoveTags().Analyze().Store()
         .Add("home_Latitude", (double)homePart.Record.Latitude).RemoveTags().Analyze().Store()
         .Add("home_Longitude", (double)homePart.Record.Longitude).RemoveTags().Analyze().Store()
          );
    }
}

This allows me to create a search service for searching through all my data and then hook it up to the model via the Concrete Property, which actually works better from a performance standpoint anyway.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!