views:

161

answers:

5

So for a new project, I'm building a system for an ecommerce site. The idea is to import products from suppliers and instead of inserting them directly into our catalog, we would store all the information in a staging area. Each supplier has their own stage (i.e. table in the database), and then I will flatten the multiple staging areas into a single entity (currently a single table but later on perhaps into Sphinx or Solr). Then our merchandisers would be able to search the staging products' relevant fields (name and description) and be shown a list of products that match and then choose to have those products pushed into the live catalog. The search will query on the single table (the flattened staging areas).

My design calls to only store searchable and filterable fields in the single flattened table - e.g. name, description, supplier_id, supplier_prod_id etc. And the search queries will return only the ID's of the items matching and a class (supplier_id) that would be used to identify which staging area the product is from.

Another senior engineer feels the flattened search table should include other meta fields (which would not be searched on), but could be used when 'pushing' the products from stage to live catalog. He also feels that the query should return all this other information.

I feel pretty strongly about only having searchable fields in the flattened table and having the search return only class/id pairs which could be used to fetch all the other necessary metadata about the product (simple select * from class_table where id in (1,2,3)).

Part of my reasoning is that this will make it easier later on to switch the flattened table from database to a search server like sphinx or solr and the rest of the code wouldn't have to be changed just because implementation of the search changed.

Am I on the right path? How can I convince the other engineer why it is important to keep only searchable fields and return only ID's? Or more specifically, why should a search application return only IDs of objects?

+2  A: 

I think that you're on the right path. If those other fields provide no value to either uniquely identify a staged item or to allow the user to filter staged items, then the data is fundamentally useless until the item is pushed to the live environment. If the other engineer feels that the extra metadata will help the users make a more informed decision, then you might as well make those extra fields searchable (thereby meeting your stated purpose for the table(s).)

The only reason I could think of to pre-fetch that other, non-searchable data would be for a performance improvement on the push to the live environment.

Jacob G
Makes sense. In my example, even if some fields are put in the 'search table', we'll still have to hit the staging area to fully gather all the necessary information before pushing live.
safoo
A: 

In the case of sphinx, it only returns document ids and named attributes back to you anyway (attributes being numerical data, for the most part). I'd say you've got the right idea as the other metadata is just a simple JOIN away from the flattened table if you need it.

Ty W
+2  A: 

You should use each tool for what it does best. A full text search engine, such as Solr or Sphinx, excels at searching textual fields and ranking the hits quickly. It has no special advantage in retrieving stored data in a select-like fashion. A database is optimized for that. So, yes, you are on the right path. Please see Search Engine versus DBMS for other issues involved in deciding what to store inside the search engine.

Yuval F
Based on your argument (search engine is better for textual fields), isn't he better to include those textual fields in the table? Since this search functionality is going to be moved to a search engine.
Bill Yang
A search engine is better for *searchable* textual fields. It has no advantage in storing text that is only meant to be displayed, not searched. Therefore, Safoo should only put in the table (and later in a search engine) the textual fields he wishes to search.
Yuval F
A: 

Hi, You can regard Solr as a powerfull index, so as an index gives IDs back, it would be logical that solr does the same.

You can use the solr query parameter fl to ask for identifier only results, for instance fl=id.

However, there's a feature that needs solr to give you back some data too: the highlighting of search terms in the matched documents. If you don't need it, then using solr to retrieve the identifiers only is fine (I assume you need only the documents list, and no other features, like facets, related docs or spell checking).

That said, it should matter how you build your objects in your search function, either from the DB using uniquely solr to retrieve IDs or from solr returned fields (providing they're stored) or even a mix of both. Think solr to get the 'highlighted' content fields and DB for the other ones. Again if you don't need highlighting, this is not an issue.

jeje
A: 

Hi, I'm using Solr with thousands of documents but only return the ids for the following reasons :

For Solr : - if some sync mistake append, it's not a big deal (especially in your case, displaying a different price can be a big issue... it's like the item will not be in the right place, but the data are right) - you will save a lot of time because when you don't ask Solr to return the 'description' of documents (I mean many lines of text)

For your DB : - you can cache your results, so it's even faster with an ID (you don't need all the data from Solr everytime !!!) - you build you results in the same way (you don't need a specific method when you want to build html from Solr, and an other method from your DB)

I think there is a lot more...

vincentp