cancel
Showing results for 
Search instead for 
Did you mean: 

Java API: How to search based on Attribute values

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Answers (2)

Answers (2)

Former Member
0 Kudos

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

Former Member
0 Kudos

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