问题描述
我目前正在一个网站上,允许用户搜索自定义产品目录.我一直在环顾四周,很乐意利用Orchard CMS来帮助我开发此网站.我目前在自定义果园模块和 Ron Petersons youtube系列中进行了浏览href ="http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-1" rel ="nofollow"> Skywalker博客系列.
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.
我觉得我的目标是可以实现的,但是我正在寻找一些验证,以确定我的策略是否可以在Orchard框架内使用.
I feel like my goal is possible, but I'm looking for some validation on whether my strategy will work within the Orchard framework.
这是我目前的情况:
-
我有一个指向SQL DB的默认Orchard配置(名为果园)
I have an default Orchard configuration pointing to a SQL DB (namedProduct-Orchard)
我有一个自定义DAL,该DAL指向另一个SQL DB(名为产品").
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).
自定义DAL具有一个称为Product的POCO模型(具有一个并与[名称],[说明],[价格]属性进行互动.
The custom DAL has a POCO model called Product (with a Repository to interact with) with the properties Name, Description, Price.
现在,根据我阅读的有关创建Orchard模块的信息,似乎使用自定义内容创建自定义模块的方法是:
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:
-
通过代码生成工具创建模块(我们将其称为ProductModule)
Create a Module through code gen tools (We'll call it ProductModule)
创建自定义内容部分(ProductPart)
Create a custom Content Part (ProductPart)
创建自定义的内容零件记录(ProductPartRecord)以用作零件的数据模型.
Create a custom Content Part Record (ProductPartRecord) to act as the data model for the part.
创建一个自定义ContentPartHandler(ProductPartHandler),用于处理内容部分的持久性.
Create a custom ContentPartHandler (ProductPartHandler) that handles the persistance of the Content Part.
创建一个自定义驱动程序,该驱动程序是用于准备Shapes以便呈现UI的条目.
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?
这是事情开始变得混乱的地方,我不确定这是否可行.我想做的是创建一个由我的自定义DAL支持的自定义内容类型,而不是通过Product-Orchard DB中的ContentPartRecord存储数据,但是仍然允许Lucene模块对其进行索引,以允许用于搜索产品目录.
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.
是否可以创建自定义ContentType和/或ContentPart并由其他数据源支持,并且仍然利用Lucene搜索功能?
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?
从高级的角度来说,我想要一个Product ContentType,其中ContentItems实际上存储在我的辅助数据库中,而不是Orchard数据库中(并且仍然希望能够通过Projections利用Lucene搜索).
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).
推荐答案
对于那些寻找相似答案的人,以下解决方案是我所基于的.我找不到简单的机制来与单独的DAL交互并执行Lucene索引.
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.
- 创建果园模块
- 通过迁移创建新的内容部件/类型
- 使用Orchard Command基础结构从辅助数据库导入数据
- 在内容部分处理程序中使用OnIndexing事件,以允许Lucene索引您的数据源.
- 创建一个查找属性(我称为mine ConcreateProperty),该属性通过在模块中创建的服务填充,以便在OnLoaded事件中与辅助DAL进行交互.
我的最终处理程序如下所示:
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()
);
}
}
这使我可以创建搜索服务来搜索我的所有数据,然后通过Concrete Property将其连接到模型,无论从性能角度来看,它实际上都表现得更好.
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.
这篇关于我可以通过Lucene在Orchard中搜索/索引自定义数据源吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!