Skip to content

Commit 28bcdbb

Browse files
rahulvudutalaMarkLogic Builder
authored andcommitted
DHFPROD-3581: Moving all ds endpoints related to entitySearch under EntitySearch Interface
1 parent 07e23ae commit 28bcdbb

File tree

17 files changed

+644
-271
lines changed

17 files changed

+644
-271
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
2-
"functionName": "getFacetValues",
2+
"functionName": "getMatchingPropertyValues",
33
"params": [
44
{
5-
"name": "entityName",
5+
"name": "entityIRI",
66
"datatype": "string"
77
},
88
{
9-
"name": "facetName",
9+
"name": "propertyPath",
1010
"datatype": "string"
1111
},
1212
{
13-
"name": "indexType",
13+
"name": "referenceType",
1414
"datatype": "string"
1515
},
1616
{
17-
"name": "searchStr",
17+
"name": "pattern",
1818
"datatype": "string"
1919
},
2020
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const lib = require('/data-hub/5/impl/hub-es.sjs');
2+
3+
var entityIRI;
4+
var propertyPath;
5+
var referenceType;
6+
var pattern;
7+
var limit;
8+
9+
var query;
10+
11+
if(referenceType === 'element') {
12+
query = cts.elementReference(propertyPath);
13+
} else if(referenceType === 'field') {
14+
query = cts.fieldReference(propertyPath);
15+
} else if(referenceType === 'collection') {
16+
query = cts.collectionReference();
17+
} else {
18+
let rangeIndexPath = lib.getPropertyRangePath(entityIRI, propertyPath);
19+
query = cts.pathReference(rangeIndexPath);
20+
}
21+
22+
var facetValues = cts.valueMatch(query, pattern + "*",
23+
["item-order", "ascending", "limit=" + limit]).toArray().map(String);
24+
25+
if (facetValues.length < limit) {
26+
var moreFacetValues = cts.valueMatch(query, "?*" + pattern + "*",
27+
["item-order", "ascending", "limit=" + limit]).toArray().map(String);
28+
facetValues = Array.from(
29+
[...new Set([...facetValues, ...moreFacetValues])]).slice(0, limit);
30+
}
31+
32+
facetValues;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"functionName": "getNumericFacetsRange",
33
"params": [
44
{
5-
"name": "entityName",
5+
"name": "entityIRI",
66
"datatype": "string"
77
},
88
{
9-
"name": "facetName",
9+
"name": "propertyPath",
1010
"datatype": "string"
1111
},
1212
{
13-
"name": "indexType",
13+
"name": "referenceType",
1414
"datatype": "string"
1515
}
1616
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const lib = require('/data-hub/5/impl/hub-es.sjs');
2+
3+
var entityIRI;
4+
var propertyPath;
5+
var referenceType;
6+
7+
var query;
8+
9+
let rangeValues = {
10+
"min": null,
11+
"max": null
12+
};
13+
14+
if(!referenceType || referenceType === "") {
15+
referenceType = lib.getPropertyReferenceType(entityIRI, propertyPath);
16+
}
17+
18+
if(referenceType === 'element') {
19+
query = cts.elementReference(propertyPath);
20+
} else {
21+
let rangeIndexPath = lib.getPropertyRangePath(entityIRI, propertyPath);
22+
query = cts.pathReference(rangeIndexPath);
23+
}
24+
25+
rangeValues.min = cts.min(query);
26+
rangeValues.max = cts.max(query);
27+
28+
rangeValues;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"endpointDirectory": "/data-hub/5/data-services/entitySearch/",
3+
"$javaClass": "com.marklogic.hub.dataservices.EntitySearchService"
4+
}

marklogic-data-hub/src/main/resources/ml-modules/root/data-hub/5/data-services/numericFacetValuesRange/numericFacetValuesRange.sjs

Lines changed: 0 additions & 22 deletions
This file was deleted.

marklogic-data-hub/src/main/resources/ml-modules/root/data-hub/5/data-services/numericFacetValuesRange/service.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

marklogic-data-hub/src/main/resources/ml-modules/root/data-hub/5/data-services/searchFacetValues/searchFacetValues.sjs

Lines changed: 0 additions & 31 deletions
This file was deleted.

marklogic-data-hub/src/main/resources/ml-modules/root/data-hub/5/data-services/searchFacetValues/service.json

Lines changed: 0 additions & 4 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
const test = require("/test/test-helper.xqy");
2+
3+
function invokeService(entityIRI, propertyPath, referenceType, pattern, limit) {
4+
return fn.head(xdmp.invoke(
5+
"/data-hub/5/data-services/entitySearch/getMatchingPropertyValues.sjs",
6+
{
7+
"entityIRI": entityIRI,
8+
"propertyPath": propertyPath,
9+
"referenceType": referenceType,
10+
"pattern": pattern,
11+
"limit": limit
12+
}
13+
));
14+
}
15+
16+
// Uncomment the tests when DHFPROD-4494 bug is resolved.
17+
/*function testMatchingValuesStartingWithPattern() {
18+
let entityIRI = "http://marklogic.com/EntitiesSearchEntity-0.0.1/EntitiesSearchEntity";
19+
let propertyPath = "numStrEntityProp/strCityProp";
20+
const result = invokeService(entityIRI, propertyPath, "path", "doc2", 10);
21+
return [
22+
test.assertEqual(2, result.length),
23+
test.assertTrue(result.includes("doc2City1Prop")),
24+
test.assertTrue(result.includes("doc2City2Prop"))
25+
];
26+
}
27+
28+
function testMatchingValuesWithPatternInBetween() {
29+
let entityIRI = "http://marklogic.com/EntitiesSearchEntity-0.0.1/EntitiesSearchEntity";
30+
let propertyPath = "numStrEntityProp/strCityProp";
31+
const result = invokeService(entityIRI, propertyPath, "path", "city", 10);
32+
return [
33+
test.assertEqual(4, result.length),
34+
test.assertTrue(result.includes("doc2City1Prop")),
35+
test.assertTrue(result.includes("doc2City2Prop")),
36+
test.assertTrue(result.includes("doc1City1Prop")),
37+
test.assertTrue(result.includes("doc1City2Prop"))
38+
];
39+
}
40+
41+
function testMatchingValuesOnRangePathOneLevelNesting() {
42+
let entityIRI = "http://marklogic.com/EntitiesSearchEntity-0.0.1/EntitiesSearchEntity";
43+
let propertyPath = "numStrEntityProp/strCityProp";
44+
const result = invokeService(entityIRI, propertyPath, "path", "city", 10);
45+
return [
46+
test.assertEqual(4, result.length),
47+
test.assertTrue(result.includes("doc2City1Prop")),
48+
test.assertTrue(result.includes("doc2City2Prop")),
49+
test.assertTrue(result.includes("doc1City1Prop")),
50+
test.assertTrue(result.includes("doc1City2Prop"))
51+
];
52+
}
53+
54+
function testMatchingValuesOnRangePathNoNesting() {
55+
let entityIRI = "http://marklogic.com/EntitiesSearchEntity-0.0.1/EntitiesSearchEntity";
56+
let propertyPath = "srchEntyProp2";
57+
const result = invokeService(entityIRI, propertyPath, "path", "city", 10);
58+
return [
59+
test.assertEqual(2, result.length),
60+
test.assertTrue(result.includes("doc1SrchEntyProp2")),
61+
test.assertTrue(result.includes("doc2SrchEntyProp2")),
62+
];
63+
}
64+
65+
function testMatchingValuesWithLimit() {
66+
let entityIRI = "http://marklogic.com/EntitiesSearchEntity-0.0.1/EntitiesSearchEntity";
67+
let propertyPath = "numStrEntityProp/strCityProp";
68+
const result = invokeService(entityIRI, propertyPath, "path", "city", 3);
69+
return [
70+
test.assertEqual(3, result.length)
71+
];
72+
}*/
73+
74+
function testMatchingValuesOnRangeElementIndexes() {
75+
let entityIRI = "http://marklogic.com/EntitiesSearchEntity-0.0.1/EntitiesSearchEntity";
76+
let propertyPath = "strNameProp";
77+
const result = invokeService(entityIRI, propertyPath, "element", "name", 10);
78+
return [
79+
test.assertEqual(4, result.length),
80+
test.assertTrue(result.includes("doc2Name1Prop")),
81+
test.assertTrue(result.includes("doc2Name2Prop")),
82+
test.assertTrue(result.includes("doc1Name1Prop")),
83+
test.assertTrue(result.includes("doc1Name2Prop"))
84+
];
85+
}
86+
87+
function testMatchingValuesOnRangeFieldIndexes() {
88+
let entityIRI = "http://marklogic.com/EntitiesSearchEntity-0.0.1/EntitiesSearchEntity";
89+
let propertyPath = "datahubCreatedInFlow";
90+
const result = invokeService(entityIRI, propertyPath, "field", "flow", 10);
91+
return [
92+
test.assertEqual(2, result.length),
93+
test.assertTrue(result.includes("my-flow-1")),
94+
test.assertTrue(result.includes("my-flow-2"))
95+
];
96+
}
97+
98+
function testMatchingValuesOnCollectionNames() {
99+
let entityIRI = "";
100+
let propertyPath = "";
101+
const result = invokeService(entityIRI, propertyPath,"collection", "doc", 10);
102+
return [
103+
test.assertEqual(2, result.length),
104+
test.assertTrue(result.includes("doc1")),
105+
test.assertTrue(result.includes("doc2"))
106+
];
107+
}
108+
109+
[]
110+
.concat(testMatchingValuesOnRangeElementIndexes())
111+
.concat(testMatchingValuesOnRangeFieldIndexes())
112+
.concat(testMatchingValuesOnCollectionNames());
113+
/*
114+
.concat(testMatchingValuesStartingWithPattern())
115+
.concat(testMatchingValuesWithPatternInBetween())
116+
.concat(testMatchingValuesOnRangePathOneLevelNesting())
117+
.concat(testMatchingValuesOnRangePathNoNesting())
118+
.concat(testMatchingValuesWithLimit())
119+
.concat(testMatchingValuesOnRangeElementIndexes())
120+
.concat(testMatchingValuesOnRangeFieldIndexes())
121+
.concat(testMatchingValuesOnCollectionNames());*/

0 commit comments

Comments
 (0)