Welcome to the new Box Support website. Check out all the details here on what’s changed.

Java SDK metadata search files available not found

New post

Comments

2 comments

  • Official comment
    Alex Novotny

    Hello, 

    Hmm. That is very odd. Can you send me the code you are running for both .net and java? I'm interested in comparing them. 

    Thanks, 

    Alex, Box Developer Advocate

    Comment actions Permalink
  • smartduck

    Hello Alex,

    The code is simple:

    Java version

    BoxSearch boxSearch = new BoxSearch(this.api);
    BoxSearchParameters boxSearchParameters = new BoxSearchParameters();
    PartialCollection<BoxItem.Info> totaalResultaat = new PartialCollection<BoxItem.Info>(0, 200, 200);

    // metadata filter opbouwen
    BoxMetadataFilter metaDataFilter = new BoxMetadataFilter();
    boxSearchParameters.clearParameters();
    boxSearchParameters.setType("file");

    // Voeg de criteria toe aan het filter
    metaDataFilter.setScope("enterprise");
    metaDataFilter.setTemplateKey(template);

    metaDataObject.keySet().forEach(keyStr ->
    {

    Object keyValue = metaDataObject.get(keyStr);
    String filterItem = BoxMetadataHashtable.getMetadataVeldSleutel(DMGStringLib.naarCamelCase(keyStr.toString())).getKey();

    metaDataFilter.addFilter(filterItem, keyValue.toString());
    });
    boxSearchParameters.setMetadataFilter(metaDataFilter);

    zoekResultaat = boxSearch.searchRange(offsetValue, limitValue, boxSearchParameters);


    .NET version


    public async Task<BoxCollection<BoxItem>> searchFilesByMetaData(BoxClient boxClient, Dictionary<string, object> searchCriteria, string templateName)
    {

    var mdFilter = new BoxMetadataFilterRequest()
    {
    TemplateKey = templateName,
    Scope = "enterprise",
    Filters = searchCriteria
    };

    // Initiate search
    return await boxClient.SearchManager.QueryAsync("", mdFilters: new List<BoxMetadataFilterRequest>() { mdFilter }, type: "file");
    }

    Regards,

    Marcel

    0
    Comment actions Permalink

Post is closed for comments.