Skip to content

Commit

Permalink
feat: relavance improved WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sercancicek committed Mar 18, 2024
1 parent b08fc22 commit b3873e8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/app/components/search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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:'overallWeight':true track by result.model.unique_id"
<div ng-repeat="result in filteredResults | 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
4 changes: 3 additions & 1 deletion src/app/components/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ angular
}
});
});
console.log("search.js: finalResults: ", finalResults);
return finalResults;
}

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);
console.log("filterResultsfilterResultsfilterResultsfilterResults");
scope.filteredResults = filterResults(scope.results, scope.checkboxStatus);
});

scope.shorten = function(text) {
Expand Down
56 changes: 53 additions & 3 deletions src/app/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,43 @@ angular
});

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

function assignSearchRelevance(results){
if($scope.search.query === "")
return results;
let criteriaArr = {
"name": 10,
"tags": 5,
"name": 5,
"tags": 4,
"description": 3,
"raw_code": 2,
"columns": 1
};
let criteriaCountDict = {
"name": 0,
"tags": 0,
"description": 0,
// "raw_code": 0,
// "columns": 0
}
_.each(results, function(result){
result.overallWeight = 0;
result.criteraCounter = {
"name": 0,
"tags": 0,
"description": 0,
"raw_code": 0,
"columns": 0
};
result.criteraWeight = {
"name": 0,
"tags": 0,
"description": 0,
"raw_code": 0,
"columns": 0
};
_.each(Object.keys(criteriaArr), function(criteria){
if(result.model[criteria] != undefined){
let count = 0;
Expand Down Expand Up @@ -197,6 +219,21 @@ angular
}
});
}
else if(criteria === "name"){
if (body === query) {
console.log("index.js: body: ", body, " query: ", query);
count += 10;
}
else if (body.toLowerCase().startsWith(query)) {
count += 5;
}
else if (body.toLowerCase().endsWith(query)) {
count += 3;
}
else if (body.toLowerCase().includes(query)) {
count++;
}
}
else{
body = body.toLowerCase();
let index = 0;
Expand All @@ -207,10 +244,23 @@ angular
}
}
}
result.criteraCounter[criteria] += count;
result.criteraWeight[criteria] += (count * criteriaArr[criteria]);
result.overallWeight += (count * criteriaArr[criteria]);
}
result.counter = criteriaCountDict;
});
});
});
console.log("index.js: before sort results: ", results);

results.sort(function(a, b) {
if (b.criteraWeight["name"] === a.criteraWeight["name"]) {
return b.overallWeight - a.overallWeight;
}
return b.criteraWeight["name"] - a.criteraWeight["name"] // Sorting by 'name' property in ascending order.
});

console.log("index.js: results: ", results);
return results;
}

Expand Down

0 comments on commit b3873e8

Please sign in to comment.