Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Nos Hs2023
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Språksamlingane
stadnamn
Nos Hs2023
Commits
3356a401
Commit
3356a401
authored
6 years ago
by
esikkala
Browse files
Options
Downloads
Patches
Plain Diff
Count number of results in hierarchical facet
parent
3cfa8955
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/client/components/Tree.js
+1
-1
1 addition, 1 deletion
src/client/components/Tree.js
src/server/sparql/Mappers.js
+19
-58
19 additions, 58 deletions
src/server/sparql/Mappers.js
with
20 additions
and
59 deletions
src/client/components/Tree.js
+
1
−
1
View file @
3356a401
...
...
@@ -157,7 +157,7 @@ class Tree extends Component {
color
=
"
primary
"
/>
}
label
=
{
node
.
title
}
label
=
{
`
${
node
.
title
}
(
${
node
.
totalCnt
==
0
?
node
.
cnt
:
node
.
totalCnt
}
)`
}
classes
=
{{
root
:
classes
.
formControlRoot
}}
...
...
This diff is collapsed.
Click to expand it.
src/server/sparql/Mappers.js
+
19
−
58
View file @
3356a401
import
_
from
'
lodash
'
;
import
{
getTreeFromFlatData
}
from
'
react-sortable-tree
'
;
//https://github.com/SemanticComputing/angular-paging-sparql-service/blob/master/src/sparql.object-mapper-service.js
...
...
@@ -130,77 +131,37 @@ export const mapFacet = (sparqlBindings) => {
parent
:
_
.
has
(
b
,
'
parent
'
,)
?
b
.
parent
.
value
:
'
0
'
,
};
});
cons
t
treeData
=
getTreeFromFlatData
({
le
t
treeData
=
getTreeFromFlatData
({
flatData
:
results
,
getKey
:
node
=>
node
.
id
,
// resolve a node's key
getParentKey
:
node
=>
node
.
parent
,
// resolve node's parent's key
rootKey
:
0
,
// The value of the parent key when there is no parent (i.e., at root level)
});
treeData
=
recursiveSort
(
treeData
);
treeData
.
forEach
(
node
=>
sumUp
(
node
));
return
treeData
;
};
/**
* Generate a tree structure from flat data.
*
* @param {!Object[]} flatData
* @param {!function=} getKey - Function to get the key from the nodeData
* @param {!function=} getParentKey - Function to get the parent key from the nodeData
* @param {string|number=} rootKey - The value returned by `getParentKey` that corresponds to the root node.
* For example, if your nodes have id 1-99, you might use rootKey = 0
*
* @return {Object[]} treeData - The flat data represented as a tree
*/
const
getTreeFromFlatData
=
({
flatData
,
getKey
=
node
=>
node
.
id
,
getParentKey
=
node
=>
node
.
parentId
,
rootKey
=
'
0
'
,
})
=>
{
if
(
!
flatData
)
{
return
[];
}
const
childrenToParents
=
{};
flatData
.
forEach
(
child
=>
{
const
parentKey
=
getParentKey
(
child
);
const
comparator
=
(
a
,
b
)
=>
a
.
title
.
localeCompare
(
b
.
title
);
if
(
parentKey
in
childrenToParents
)
{
childrenToParents
[
parentKey
].
push
(
child
);
}
else
{
childrenToParents
[
parentKey
]
=
[
child
];
const
sumUp
=
node
=>
{
node
.
totalCnt
=
parseInt
(
node
.
cnt
);
if
(
_
.
has
(
node
,
'
children
'
))
{
for
(
let
child
of
node
.
children
)
{
node
.
totalCnt
+=
sumUp
(
child
);
}
});
if
(
!
(
rootKey
in
childrenToParents
))
{
return
[];
}
return
node
.
totalCnt
;
};
const
trav
=
parent
=>
{
const
parentKey
=
getKey
(
parent
);
if
(
parentKey
in
childrenToParents
)
{
return
{
...
parent
,
children
:
childrenToParents
[
parentKey
].
map
(
child
=>
trav
(
child
)),
};
const
recursiveSort
=
nodes
=>
{
nodes
.
sort
(
comparator
);
nodes
.
forEach
(
node
=>
{
if
(
_
.
has
(
node
,
'
children
'
))
{
recursiveSort
(
node
.
children
);
}
return
{
...
parent
};
};
const
comparator
=
(
a
,
b
)
=>
a
.
title
.
localeCompare
(
b
.
title
);
const
recursiveSort
=
nodes
=>
{
nodes
.
sort
(
comparator
);
nodes
.
forEach
(
node
=>
{
if
(
_
.
has
(
node
,
'
children
'
))
{
recursiveSort
(
node
.
children
);
}
});
return
nodes
;
};
const
unsortedTreeData
=
childrenToParents
[
rootKey
].
map
(
child
=>
trav
(
child
));
return
recursiveSort
(
unsortedTreeData
);
});
return
nodes
;
};
export
const
mapAllResults
=
(
results
)
=>
groupBy
(
results
,
'
id
'
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment