Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Media Bin 4.5 Webservices .Net Search Examples
ferg
Hello. I have the WebServices API documentation, but, given the lack of explanation of certain fields related to the search (specifically members of the MBMetaData object), I would find it useful to have some examples using the Search webmethod. Right now, I'm relegated to trial and error, and it's slow going.
I have the C# sample code for 4.0, but it has no Search samples, nor can I compile it when referencing version 4.5 of the web service.
Any help greatly appreciated.
Thanks,
CF
Find more posts tagged with
Comments
msnider
Check out the following post for a discussion and sample code on how to perform a MediaBin search from Java:
http://devnet.interwoven.com/forums/cgi-bin/showflat.pl?Cat=&Board=PRODUCTS_MEDIABIN&Number=45496&page=4&view=collapsed&sb=5&o=0&part=
Also, here is the C# version of the sample search code detailed in the above post:
public static string[] SearchByName( string name, string containerID, int maxHits, bool bRecursive, bool bExactMatch, bool bReturnNames, MediaBinServer mMediaBinServer)
{
MBSearchCriteria criteria = new MBSearchCriteria();
criteria.mContainerID = containerID;
criteria.mAssetID = null;
criteria.mRecursive = bRecursive;
criteria.mMaxHits = maxHits;
MBMetadata metadata = new MBMetadata();
metadata.mName = "Name";
metadata.mID = "{B297C571-F083-11D4-8200-0060080D8AC2}";
metadata.mValue = name;
MBSearchConstraint[] constraints = new MBSearchConstraint[1];
constraints[0] = new MBSearchConstraint();
constraints[0].mMetadata = metadata;
if( bExactMatch )
constraints[0].mSearchOperator = "Equality";
else
constraints[0].mSearchOperator = "Contains";
constraints[0].mBooleanOperator = MBBooleanOperator.NotSet;
criteria.mSearchConstraints = constraints;
string[] ids = null;
if( !bReturnNames )
{
ids = mMediaBinServer.Search_GetAssetIDsOnly( criteria );
}
else
{
MBAsset[] assets = mMediaBinServer.Search( criteria, false );
if( assets != null && assets.Length > 0 )
{
ids = new string[assets.Length];
for(int i=0; i< assets.Length; i++)
{
//Format string info
string str = "Asset #" + i;
str += "\nName: " + assets
.mName;
str += "\nPath: " + assets
.repositoryPath + "\n\n";
ids
= str;
}
}
}
return ids;
}
There should be a 4.5 compatible version of the SDK available on the support site. However, you can also use the 4.0 version as long as you update the web reference as the WSDL has changed.
Mark
ferg
A couple of questions...
In this segment of code:
MBMetadata metadata = new MBMetadata();
metadata.mName = "Name";
metadata.mID = "{B297C571-F083-11D4-8200-0060080D8AC2}";
metadata.mValue = name;
What is the mID being passed in there? Is that a GUID for that actual metadata field?
Also, would it possible to get some more examples, specifically, examples that search multiple fields for multiple values?
Something like if the name was x OR y AND field2 was a OR b, that sort of thing?
msnider
Yes, the mID is the identifier (GUID) of the actual metadata that you are searching on. You can get these ids as well as the valid search operators by calling the webmethod GetSearchableMetadata.
To do a search using mulitple values, you build the MBSearchConstraint array to hold the individual search constraints...i.e. to search on Asset Name contains "North America" OR Asset Name contains "Europe" AND Asset Type is JPEG, you would do the following:
MBMetadata metadata0 = new MBMetadata();
metadata0.mName = "Name";
metadata0.mID = "{B297C571-F083-11D4-8200-0060080D8AC2}";
metadata0.mValue = "North America";
MBMetadata metadata1 = new MBMetadata();
metadata1.mName = "Name";
metadata1.mID = "{B297C571-F083-11D4-8200-0060080D8AC2}";
metadata1.mValue = "Europe";
MBMetadata metadata2 = new MBMetadata();
metadata2.mName = "Asset Type";
metadata2.mID = "{4510D310-E6BB-11D2-BF95-00A024DB7160}";
metadata2.mValue = 1; //JPEG
MBSearchConstraint[] constraints = new MBSearchConstraint[3];
constraints[0] = new MBSearchConstraint();
constraints[0].mMetadata = metadata0;
constraints[0].mSearchOperator = "Contains";
constraints[0].mBooleanOperator = MBBooleanOperator.OR;
constraints[1] = new MBSearchConstraint();
constraints[1].mMetadata = metadata1;
constraints[1].mSearchOperator = "Contains";
constraints[1].mBooleanOperator = MBBooleanOperator.AND;
constraints[2] = new MBSearchConstraint();
constraints[2].mMetadata = metadata2;
constraints[2].mSearchOperator = "Equality";
constraints[2].mBooleanOperator = MBBooleanOperator.NotSet;
criteria.mSearchConstraints = constraints;
Mark
ferg
Okay...again, very helpful.
Here's the thing, though - how do the constraints get grouped?
In your example, is it effectively doing (AssetName contains "North America" OR AssetName contains "Europe") and AssetType = 1
..or is it doing AssetName contains "North America" OR (AssetName contains "Europe" and AssetType=1)
Maybe I should clarify...what I really need to do is a search where the search criteria is built along these lines:
(CustomField1=value1 or CustomField1=value2 or CustomField1=value3) AND (CustomField2=value4 or CustomField2=value5 or CustomField2=value6)
Is there any way to do this?
msnider
The constraints are grouped in pairs from left to right. So, in the example the contraints are grouped as (AssetName contains "North America" AND AssetType = 1) OR (AssetName contains "Europe" AND AssetType = 1) which is the same as (AssetName contains "North America" OR AssetName contains "Europe") and AssetType = 1.
Therefore, you can accomplish the search that you want by expanding the equation such that
( C1 OR C2 OR C3 ) AND ( C4 OR C5 OR C6 )
becomes
( C1 AND C4 ) OR ( C1 AND C5 ) OR ( C1 AND C6 ) OR ( C2 AND C4 ) OR ( C2 AND C5 ) OR ( C2 AND C6 ) OR ( C3 AND C4 ) OR ( C3 AND C5 ) OR ( C3 AND C6 )
where Cn are your constraints.
Mark
ferg
Yikes. Everything is done in pairs?
Is there no way to do a more elaborate grouping?
What if I had three groups
(c1 or c2 or c3) and (c4 or c5 or c6) and (c7 or c8 or c9)
There's no way to translate that down into pairs, since at least 3 of the constraints need to be met....
msnider
Unfortunately no, there is no way to specify a more elaborate grouping....in fact, all of the MediaBin clients, including the web service, use that method. However, I believe the lower-level APIs, such as the C++ or the COM API should allow you to specify your own grouping method.
As a workaround for the webservice, you could split your search into three separate searches such that
Search 1: (c1 or c2 or c3)
Search 2: (c4 or c5 or c6)
Search 3: (c7 or c8 or c9)
and then take the intersection of the result sets. In this case, I'd use Search_GetAssetIDsOnly so that you only have to compare IDs.
Mark