Skip to content

Commit

Permalink
Searchable column descriptions (#371)
Browse files Browse the repository at this point in the history
* Enable searching column descriptions

* Give the tag checkbox a unique id

* Fix typos

* Changelog entry
  • Loading branch information
dbeatty10 authored Feb 17, 2023
1 parent 8b525e4 commit ddd7fd9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Docs-20230209-212729.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Docs
body: Searchable column descriptions
time: 2023-02-09T21:27:29.570243-07:00
custom:
Author: dbeatty10
Issue: 140 322 369
4 changes: 3 additions & 1 deletion src/app/components/search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ <h1>
<label for="desc" style="margin-right:25px;">Description</label>
<input type="checkbox" id="column" ng-model="checkboxStatus.show_columns" ng-click = "filterResults(results, checkboxStatus)" style = "margin-right:5px">
<label for="column" style="margin-right:25px;">Column</label>
<input type="checkbox" id="column_description" ng-model="checkboxStatus.show_column_descriptions" ng-click = "filterResults(results, checkboxStatus)" style = "margin-right:5px">
<label for="column_description" style="margin-right:25px;">Column Description</label>
<input type="checkbox" id="code" ng-model="checkboxStatus.show_code" ng-click = "filterResults(results, checkboxStatus)" style = "margin-right:5px">
<label for="code" style="margin-right:15px;">SQL</label>
<input type="checkbox" id="code" ng-model="checkboxStatus.show_tags" ng-click = "filterResults(results, checkboxStatus)" style = "margin-right:5px">
<input type="checkbox" id="tag" ng-model="checkboxStatus.show_tags" ng-click = "filterResults(results, checkboxStatus)" style = "margin-right:5px">
<label for="code" style="margin-right:15px;">Tags</label>
</div>
</div>
Expand Down
8 changes: 5 additions & 3 deletions src/app/components/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ angular
show_names : false,
show_descriptions: false,
show_columns: false,
show_column_descriptions: false,
show_code: false,
show_tags: false
};
Expand Down Expand Up @@ -62,17 +63,18 @@ angular
let finalResults = [];
let fileIDs = [];

const {show_names, show_descriptions, show_columns, show_code, show_tags} = checkboxStatus;
const {show_names, show_descriptions, show_columns, show_column_descriptions, show_code, show_tags} = checkboxStatus;
_.each(results, function(result){
_.each(result.matches, function(match){
if(!fileIDs.includes(result.model['unique_id'])){
const nameMatch = show_names && (match.key === "name" || match.key == 'label');
const descriptionMatch = show_descriptions && match.key == "description";
const columnsMatch = show_columns && match.key === "columns";
const columnDescriptionMatch = show_column_descriptions && match.key === "column_description";
const codeMatch = show_code && match.key === "raw_code";
const tagsMatch = show_tags && match.key === "tags";

if(nameMatch || descriptionMatch || columnsMatch || codeMatch || tagsMatch) {
if(nameMatch || descriptionMatch || columnsMatch || columnDescriptionMatch || codeMatch || tagsMatch) {
fileIDs.push(result.model['unique_id']);
finalResults.push(result);
}
Expand All @@ -82,7 +84,7 @@ angular
return finalResults;
}

var watchExpressions = ['query', 'checkboxStatus.show_names', 'checkboxStatus.show_descriptions', 'checkboxStatus.show_columns', 'checkboxStatus.show_code', 'checkboxStatus.show_tags'];
var watchExpressions = ['query', 'checkboxStatus.show_names', 'checkboxStatus.show_descriptions', 'checkboxStatus.show_columns', 'checkboxStatus.show_column_descriptions', 'checkboxStatus.show_code', 'checkboxStatus.show_tags'];
scope.$watchGroup(watchExpressions, function() {
scope.results = filterResults(projectService.search(scope.query), scope.checkboxStatus);
});
Expand Down
16 changes: 14 additions & 2 deletions src/app/services/project_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ angular
'description':'string',
'raw_code':'string',
'columns':'object',
'column_description':'n/a', // special case
'tags': 'array',
'arguments': 'array',
'label': 'string',
Expand All @@ -274,13 +275,24 @@ angular
let query_segments = _.words(query.toLowerCase());

for (var i in search_keys) {
if (!obj[i]) {

// column descriptions are a special case because they are not a top-level key
if (i === 'column_description') {
for (var column_name in obj["columns"]) {
if (obj["columns"][column_name]["description"] != null) {
if (query_segments.every(segment => obj["columns"][column_name]["description"].toLowerCase().indexOf(segment) != -1)) {
objects.push({key: i, value: query});
}
}
}
} else if (!obj[i]) {
// skip any other cases where the object is missing the key
continue;
} else if (search_keys[i] === 'string' && query_segments.every(segment => obj[i].toLowerCase().indexOf(segment) != -1)) {
objects.push({key: i, value: query});
} else if (search_keys[i] === 'object') {
for (var column_name in obj[i]) {
// there a spark bug where columns are missign from the catalog. That needs to be fixed
// there is a spark bug where columns are missing from the catalog. That needs to be fixed
// outside of docs but this if != null check will allow docs to continue to function now
// and also when the bug is fixed.
// relevant issue: https://github.com/dbt-labs/dbt-spark/issues/295
Expand Down

0 comments on commit ddd7fd9

Please sign in to comment.