on 09-02-2005 11:06 AM
Hi All,
Can anyone tell me how to search based on <b>Attribute values</b> of a category through JAVA API.
Thanks in advance,
Ananth
Hi Ananth,
For feature attribute based search you must know the Attributes and Features' Id. This chunk of code may help you to search based on features:
FeatureDomain featureDomain = attribute.GetFeatures();
FeatureValue featureValue = null;
for(int i=0;i<featureDomain.GetCount();i++){
featureValue = featureDomain.GetFeatureValueAt(i);
if(featureValue.GetValue().equals("No")){
break;
}
}
int attributeId = attribute.GetID();
FeatureParameter atrParam= new FeatureParameter(attributeId);
atrParam.Add(featureValue.GetID());
txParameter.Add(atrParam);
Regards
Shahid Nadeem
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Saheed Nahim,
Thanks a lot for your reply.
I am trying to search based on Feature values [Text] and I tried using the following code for a category called "Screwdriver Sets" and attribute "Tip Type".
FeatureParameter fp = new FeatureParameter(attribute.GetID());
FeatureValue fv = new FeatureValue("Tamper Proof");
fp.Add(fv.GetID());
txParameter.Add(fp);
This code is not filtering records baesd on the attribute value "Tamper Proof".
So do we need to use anything like..
FreeFormAttributeParameter ffap = new FreeFormAttributeParameter(attribute.GetID(),CMRatingType.NominalRating,FreeFormAttributeParameter.EqualToSearchType);
<b>or</b>
FreeFormFeatureValueParameter ffvp = new FreeFormFeatureValueParameter("Tip Type",FreeFormParameter.EqualToSearchType);
Thanks,
Ananth
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ananth,
As you might know that there three types of attributes, i) Text, ii) Numeric, and iii) Coupled Numeric. See sample code to search based on Numeric attribute values of a category.
public static void main(String[] args) throws StringException {
String productTable = "Products";
String taxonomyFieldInProductTable = "Categories";
String taxonomyTable = "Taxonomy";
String taxonomyField = "Name";
Search search = new Search(productTable);
TaxonomyLookupParameter txParameter = new TaxonomyLookupParameter(productTable, taxonomyFieldInProductTable);
search.Add(txParameter);
//to get category/taxonomy record id
int categoryID = getRecordID(taxonomyTable, taxonomyField, "Electronic");
txParameter.SetNodeID(categoryID);
AttributeInfoArray attributes = catalogData.GetLinkedAttributesForTaxonomy(taxonomyTable, categoryID, true);
AttributeInfo attribute = null;
for (int attribIndex = 1; attribIndex < attributes.GetCount(); attribIndex++) {
attribute = attributes.GetAttributeInfoAt(attribIndex);
System.out.println("Attribute Name:'" + attribute.GetName() + "'");
//check whether this is the required attribute
if (attribute.GetName().equals("Depth")) {
break;
}
}
CharacteristicParameter atrParam = new CharacteristicParameter(attribute.GetID(), CMRatingType.NominalRating);
CharacteristicValueParameter cValueParam = new CharacteristicValueParameter();
cValueParam.SetValue(0.70);
cValueParam.SetUnitID((byte) attribute.GetDefaultUnitID());
atrParam.Add(cValueParam);
txParameter.Add(atrParam);
ResultSetDefinition rsd = new ResultSetDefinition(productTable);
rsd.AddField("SKU");
A2iResultSet rs = catalogData.GetResultSet(search, rsd, null, true, 0);
System.out.println("Number of records found: " + search.GetNumSearchTableResults());
for (int i = 0; i < rs.GetRecordCount(); i++) {
Value partNumnerValue = rs.GetValueAt(i, "SKU");
System.out.println("PartNumber: " + partNumnerValue.GetStringValue());
}
}
private static int getRecordID(String table, String displayField, String value) throws StringException {
A2iStringArray values = new A2iStringArray();
values.Add(value);
ResultSetDefinition rsd = new ResultSetDefinition(table);
rsd.AddField(displayField);
A2iResultSet rs = null;
rs = catalogData.GetRecordsByValue(values, rsd, displayField);
if (rs.GetRecordCount() > 0) {
return rs.GetRecordIDAt(0);
}
return -1;
}
Regards
Shahid Nadeem
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
11 | |
10 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.