I am currently working on a site to allow users to search through a custom product catalog. I have been looking around and would love to leverage Orchard CMS to help me develop this site. I have currently gone through Ron Petersons youtube series on custom Orchard Modules and the Skywalker blog series.
I feel like my goal is possible, but I'm looking for some validation on whether my strategy will work within the Orchard framework.
This is my current situation:
I have an default Orchard configuration pointing to a SQL DB (named Product-Orchard)
I have a custom DAL that points to another SQL DB (named Products).
Products are made up of your typical information (Product Name, Description, Price, etc).
The custom DAL has a POCO model called Product (with a Repository to interact with) with the properties Name, Description, Price.
Now, based on the information I read about creating Orchard modules it seems like the method of creating a custom module with custom content is to:
Create a Module through code gen tools (We'll call it ProductModule)
Create a custom Content Part (ProductPart)
Create a custom Content Part Record (ProductPartRecord) to act as the data model for the part.
Create a custom ContentPartHandler (ProductPartHandler) that handles the persistance of the Content Part.
Create a custom Driver that is the entry for preparing the Shapes for rendering of the UI.
Potentially create a Service that interacts with the Drivers?
This is where things start to get jumbled and I'm not sure if this is possible or not. What I would like to do is to create a custom Content Type that is backed by my custom DAL rather than having the data be stored through the ContentPartRecord inside the Product-Orchard DB, but still allow it to be indexed by the Lucene module to allow for searching of the Product catalog.
Is it possible to create a custom ContentType and/or ContentPart that is backed by a different datasource and still leverage the Lucene search capabilities?
In high level terms I'd like a Product ContentType where the ContentItems are actually stored in my secondary database, not the Orchard database (and still want to be able to leverage Lucene search via Projections).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With