@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