I have a products table on my database, and a table with features of this products. The features table have 3 columns: id, type and value. Id is 开发者_如何学Pythona foreign key from products. A example of data on my tables: Table Products:
ID | Description |
01 Computer A
02 Car
03 Computer B
Table Features:
ID | Type | Value |
01 Processor Phenom X3
01 Memory 2GB
01 HDD 500GB
02 Color Blue
02 Mark Ford
03 Processor Phenom X3
03 Memory 3GB
I want the best way to index it, so, a example, when someone searches for “computer”, the faceting shows:
Phenom X3(2)
Memory 2GB(1)
Memory 3GB(1)
HDD 500GB(1)
And so on, related with the query string. If I make a query with the string “processor”, it will list Phenom X3(1) only if this products (with “processor” on description) have a feature like Processor: Phenom X3. There’s a lot of product types, so we can’t create static colums to all features and pass it to Solr… I hope my question is clear, thanks in advance!
Use data import handler to index the data @ http://wiki.apache.org/solr/DataImportHandler
You can define the products table as main entity and features as sub entity. So that the product with features is indexed as a single document.
For indexing - Define description field as indexed true As you want facet on type and value, you can define a new field type_value with type string and concat the type and value field in dataconfig.xml type_value will be a multivalued field.
For searching -
Make the product description field searchable e.g. q=description:computers
You can configure this in the solrconfig.xml with proper weightage
Define the features field as a facet field and facet.field=type_value
I hope this gives a fair idea.
精彩评论