Search code examples
javasharepointmicrosoft-graph-api

Search for files using Yes/No Custom Column, using GraphApi in Java


Is there a way i can do a search for files in a sharepoint site using a Custom Yes/No Column named Tagged? I am working with Java GraphApi SDK

It tried this but i does not seem to work, this is my base code so far. when i add the search tearm for the tagged field everything stop working. You can see the query with the tagged field in the second query string

SiteRequestBuilder sitereq = graphClient.sites(siteid);
String webUrl = sitereq.buildRequest().get().webUrl;
String queryString = String.format("isDocument=true AND processed=false AND path: \"%s\" ", webUrl);
String queryStringTagged = String.format("STTagged=false AND isDocument=true AND processed=false AND path: \"%s\" ", webUrl);

LinkedList<SearchRequest> requestsList = new LinkedList<>();
SearchRequest requests = new SearchRequest();

LinkedList<EntityType> entityTypesList = new LinkedList<>();
entityTypesList.add(EntityType.DRIVE_ITEM);
requests.entityTypes = entityTypesList;

LinkedList<SortProperty> sortProperties = new LinkedList<>();
SortProperty sort = new SortProperty();
sort.name = "LastModifiedTime";
sort.isDescending = false;
sortProperties.add(sort);

SearchQuery query = new SearchQuery();
query.queryString = queryString;
requests.query = query;
requests.sortProperties = sortProperties;
requests.size = 500;

requestsList.add(requests);

SearchEntityQueryParameterSet sqp = SearchEntityQueryParameterSet
                .newBuilder()
                .withRequests(requestsList)
                .build();

SearchEntityQueryCollectionRequest searchRequest = graphClient.search().query(sqp).buildRequest();
SearchEntityQueryCollectionPage searchResult = searchRequest.post();

Solution

  • i was able to do this by searching for the index field associated with it

    String queryStringTagged = String.format("STTagged=false AND isDocument=true AND RefinableString09=false AND path: \"%s\" ", webUrl);