I want to create a OSDK-query from slate with a filter to a set of values

I’m failing to write a query in Slate that filters the result to a set of names. (OSDK)

The task seems to be fairly easy:
I have and array of rids = [“rid1.223”, “rid2.222”]

Searching by one filter works well:

const result = ObjType
    .where(query => query.tableName.eq("rid1.223"))
    .fetchPage();

return result

I cannot (or want not) to use the function “containsAnyTerm” because the searchterms contain dots and quotes. (And because I want to learn how to do this filtering…)

result = ObjType
    .where(query => query.tableName.containsAnyTerm(rids.join(","))
    .fetchPage();

Any advice how I can implement such a filter?

The slate team is working on improving exposed OSDK functionality and better documentation, but in the meantime you can use Filtering Operations using the following code. Please note though that this functionality is undocumented and may change as the Slate team iterates on OSDK support.

import OSDK from "@slate-internal/sdk";

result = ObjType
    .where(query => {
        return OSDK.Op.or(
            query.tableName.eq("rid1.222"),
            query.tableName.eq("rid1.223")
        )
    })
    .fetchPage();

Thanks!

Your code did not compile (missing bracket), but brought me to the right direction.

The task was as well to treat a list of rids. Here how I finally solved it:

import { client } from "@slate/osdk";
import OSDK from "@slate-internal/sdk";

const ObjType = client.ontology.objects.XXX

let tableNames = ["aaa", "bbb"]


let result = await ObjType
    .where(query => {
		let tableConditions = tableNames.map(element => query.tableName.eq(element))
        return OSDK.Op.or(...tableConditions)
    })
    .fetchPage();

return result

@jchomicki Yes, the API needs to be documented and …sigh why again a new form of the API? The SearchRequest from Phonograph2 was not too beatiful but worked (and like me there are people on many stacks that implemented a set of functions to create these Phonograph/Elasticsearch queries.

So what I did now is a small translator, that translates from the Phonograph SearchRequest to the OSDK calls. (traversing the tree)
I concentrated at first on the AND / OR and for sure the SearchRequest

/**
 * The OSDK to phono-Lib
 *  Allows to use OSDK queries using the phonograph SearchQuery Syntax
 */
function execOSDKQueryBySearchFilter(ontologyObjectType, phonoFilter) {
	let result = ontologyObjectType.where(query => {
			let filter = getOSDKFilter(query, phonoFilter)
			return filter
		})
		.fetchPage();

	return result
}


/**
 * returns a OSDK-Filterobject from a node inside of a phonograph
 * SearchFilter Object 
 * /workspace/documentation/developer/api/phonograph2/objects/com.palantir.phonograph2.api.SearchFilter
 * 
 */
function getOSDKFilter(query, filterNode) {

	let nodeType = filterNode.type
	
	switch(nodeType) {
		case "queryString": {
			// the basic....
			filter = filterNode.queryString
			return query[filter.field].eq(unQuote(filter.queryString))
			break;
		}
		case  "or": {
			let conditions = filterNode.or
			let conditionQueries = conditions.map(element => getOSDKFilter(query, element))
			return OSDK.Op.or(...conditionQueries)
			break;
		}
		case  "and": {
			let conditions = filterNode.and
			let conditionQueries = conditions.map(element => getOSDKFilter(query, element))
			return OSDK.Op.and(...conditionQueries)
			break;
		}
		case  "rawOSDK": {
			return filterNode.OSDKfunction(query)
			break;
		}


		default:
			//   code block
	}
} 


function unQuote(aString) {
	if (aString.substring(0,1) == "\"" &&
		aString.substring(aString.length - 1) == "\"")
	return aString.substring(1, aString.length - 1)
}

Having this I can re-use my utility functions:

filter = {
	"type": "and",
  	"and": []
}
filter.and.push (		
	createFilterListFromMultiselect(
		"tableName", ["a", "b"] 
		))

filter.and.push (		
	createQueryStringFilter("project", "c")
	)

return await execOSDKQueryBySearchFilter(objType, filter)

To avoid re-coding all the different operators and allow to benefit from new operators, I opened the door to the raw OSDK filters. It can be combined with the others as well:

filter = {
  "type": "rawOSDK",
  "OSDKfunction": function (query) {
    return query.tableName.eq("quintiq_cw")
  }
}

return await execOSDKQueryBySearchFilter(objType, filter)

One last comment:
I really dislike the containsAnyTerm. Here the doc from https://www.palantir.com/docs/foundry/ontology-sdk/java-osdk/

  • value string: White-space separated set of words to match on. For example, “foo bar” will match “bar baz” but not “baz qux”.

What a bad design! What if some wants to search for terms with a space? If I want to search for a array of keywords, I want to pass the keywords as an array!
Please adapt the function that it allows as well passing an array