Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search relevance criteria to DBT search function #113

Merged
merged 4 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/components/search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1>
<div class="app-details">
<div class="app-frame app-pad">
<div class="results">
<div ng-repeat="result in results | filter:limit_search | orderBy:'-model.name':true track by result.model.unique_id"
<div ng-repeat="result in results | filter:limit_search | orderBy:'overallWeight':true track by result.model.unique_id"
data-ui-state="getState(result.model)" data-ui-state-params="{unique_id: result.model.unique_id}"
ng-click="onSelect()"
class="result search-result a">
Expand Down
61 changes: 60 additions & 1 deletion src/app/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,69 @@ angular
}
});


$scope.$watch('search.query', function(q) {
$scope.search.results = projectService.search(q);
$scope.search.results = assignSearchRelevance(projectService.search(q));
});

function assignSearchRelevance(results){
if($scope.search.query === "")
return results;
let criteriaArr = {
"name": 10,
"tags": 5,
"description": 3,
"raw_sql": 2,
"columns": 1
};
_.each(results, function(result){
result.overallWeight = 0;
_.each(Object.keys(criteriaArr), function(criteria){
if(result.model[criteria] != undefined){
let count = 0;
let body = result.model[criteria];
let query = ($scope.search.query).toLowerCase();
if(criteria === "columns"){
_.each(body, function(column){
let columnName = column.name.toLowerCase();
let index = 0;
while(index != -1){
index = columnName.indexOf(query, index);
if (index != -1) {
count++; index++;
}
}
});
}
else if(criteria === "tags"){
_.each(body, function(tag){
let tagName = tag.toLowerCase();
let index = 0;
while(index != -1){
index = tagName.indexOf(query, index);
if (index != -1) {
count++; index++;
}
}
});
}
else{
body = body.toLowerCase();
let index = 0;
while(index != -1){
index = body.indexOf(query, index);
if(index != -1){
count++; index++;
}
}
}
result.overallWeight += (count * criteriaArr[criteria]);
}
});
});
return results;
}


/*
INITIALIZE THE APPLICATION:
Expand Down