Advanced Searching... Seperate Search class or function in my Object Collection

Advanced Searching... Seperate Search class or function in my Object Collection

Old forum URL: forums.lhotka.net/forums/t/142.aspx


ltgrady posted on Thursday, May 18, 2006

We have a Product object.  This object has about 360 properties.  I know that's a lot, but it is what it is.  our database stores a lot of information about each product.  Not every customer uses every property, but at least someone uses each property in our db.  We have talked about trying to create lazy loaded objects or subclassing, but that's a different discussion for a different day.  For now just know that it's a very large object.  It's switchable.  Sometimes we have a Products Collection and sometimes we work with just a Product Object.

Right now we retrieve Products by only two criteria.  Either it's Brand_ID or the Product_ID.  (eg.  a 2GB Nano (Product) would be in the (Products) collection retrieve when we pass in the Apple (Brand) ).  That Product holds all the technical specs, shipping specs, dimensions, prices, etc., etc., etc..

We have finished the Data Entry portion of our system but now we're moving on to searching and reporting.  We need to be able to search through a customers products by a wide range of Criteria.  Not just Product_ID and Brand_ID, but perhaps by Weight, Price Ranges, Manufacturing Country, Product Category, and on and on.

We are creating a WEb Service so that our customers who want to power their websites product search using our database can just consume it instead of what we used to do, hosting their search results page.  So we don't want to pass these gigantic objects back and forth to the users.

SO, finally, my question.  I don't think the proper way to go about this would be to blow out the Criteria section of my Product object and try putting all the possible search fields into in and having dozens of overriden GetProducts methods.

We're thinking of some kind of Search class where each criteria is actually a property.  Then the property builds a WHERE clause that's passed in as the CSLA Criteria.  Then returning an object.  WE're not sure what to pass back.  Sometimes our clietns will only want the basic Model, Brand, price, Image URL.  Other times they'll want a very detailed Export for their systems.  We actually have a Field Group class and system for data entry where the user selects the "Field Grouping" they want and then we dynamically build a GridView in memory and show juse the fields they want.  But that's bound to teh big fat Product object with all fields.  A little kludgy.  WE don't want to pass that back.  Maybe I could dynamically generate a class based on the field group.  I don't know.

 

I was wondering if anyone had any suggestions or has done anything like this in the past and could lend some insight.  At the very least it's an intersting object discussion.  Thanks, lg.

MichaelBosch replied on Thursday, May 18, 2006

There's a few ways to accomplish this type of functionality.  Alot of this can take place in the database as well.  Perhaps you could create an object ProductCatalog that has a Search method that accepts a simple string.  This will send search for the product looking for a match in any of the fields of the product.  Or perhaps you want an overload of that Search method that accepts a key-value object where you have matched a Property Name of PropertyDescriptor object, with the value you want for it.  Something like:

ProductName|"ipod"
ProductPrice|20.00
ProductSKU| "IPO3330"

Then you can build a dynamic query from that.  If the property name is repeated, this could signal an "OR" statement in the query.  This search method will probably return a ProductMatches collection, each item would have a GetProduct method to get the "actual" business object. 

If you need more flexibility, I would definitely download the Amazon Web Services API documentation just to get a better idea of a well designed, highly customizable search engine API.

Copyright (c) Marimer LLC