Can I search / index my own data source in Orchard via Lucene?

I am currently working on a site so that users can search the userโ€™s product catalog. I searched around and would like to use Orchard CMS to help me develop this site. Currently, I have gone through the Ron Petersons youtube series on the custom modules Orchard and Skywalker blog .

I feel that my goal is possible, but I am looking for some verification of whether my strategy will work within Orchard.

This is my current situation:

  • I have a default Orchard configuration pointing to SQL DB (named Garden Product)

  • I have a custom DAL that points to another SQL database (named products).

  • Products consist of your typical information (product name, description, price, etc.).

  • The custom DAL has a POCO model called Product (interact with the repository) with the Name, Description, Price properties.

Now, based on the information I read about creating Orchard modules, it seems like the method for creating a custom module with custom content is:

  • Create a module using code tools (we will call it ProductModule)

  • Create a custom piece of content (ProductPart)

  • Create a custom content part record (ProductPartRecord) to act as a data model for the part.

  • Create your own ContentPartHandler (ProductPartHandler) that handles the persistence of a piece of content.

  • Create your own driver, which is the entry for preparing the forms for displaying the user interface.

  • Potentially create a service that interacts with drivers?

Here everything starts to get in the way, 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 supported by my custom DAL, and not to store data through the ContentPartRecord inside the DB Product-Orchard, but still allow it to be indexed by the Lucene module to allow search in the product directory.

Is it possible to create a custom ContentType and / or ContentPart that is supported by another data source and still uses Lucene's search capabilities?

In high-level terms, I need a ContentType for content where ContentItems are actually stored in my secondary database and not in the Orchard database (and still want to be able to use Lucene search through Projections).

+6
source share
1 answer

For those looking for a similar answer, the next solution is where I left off. There is no simple mechanism that I could find to interact with a single DAL and perform Lucene indexing.

  • Create a gardener module
  • Create a new piece of content / type through aMigration
  • Using the Orchard Command infrastructure to import data from your secondary database
  • Use the OnIndexing event in the Content Part handler so Lucene can index your data source.
  • Create a search property (I called my ConcreateProperty) that populates the I service created in the module to interact with the secondary DAL in the OnLoaded event.

My last 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 to search all of my data, and then connect it to the model through the Concrete property, which in any case works better in terms of performance.

+7
source

Source: https://habr.com/ru/post/951563/


All Articles