Skip to content

Commit

Permalink
initial cut of browsing documents by tag
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrudnick committed Sep 16, 2013
1 parent 2b22ffe commit 9823253
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ config(['$locationProvider','$routeProvider',
$routeProvider.
when('/search', {templateUrl: 'partials/search.html', controller: SearchCtrl}).
when('/searchresults/:query', {templateUrl: 'partials/searchresults.html', controller: SearchCtrl}).
when('/bytag/:query', {templateUrl: 'partials/bytag.html', controller: ByTagCtrl}).
when('/upload', {templateUrl: 'partials/upload.html', controller: UploadCtrl}).
when('/catalog', {templateUrl: 'partials/catalog.html', controller: CatalogCtrl}).
otherwise({redirectTo: '/search'});
Expand Down
28 changes: 27 additions & 1 deletion app/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,35 @@ function SearchCtrl($scope, $http, $location, $routeParams, TotalFiles) {
};

$scope.totalDocs = TotalFiles.get();

}

function ByTagCtrl($scope, $http, $location, $routeParams, TotalFiles) {
$scope.$routeParams = $routeParams;

$scope.query = $routeParams.query;

$scope.fetch = function() {
$scope.code = null;
$scope.response = null;
// XXX: should maybe be post?
// , cache: $templateCache}).
$http({method: "get", url: "etiqueta/" + $scope.query}).
success(function(data, status) {
$scope.results = data;
}).
error(function(data, status) {
alert("search failya");
});
};

$scope.jumpToResults = function() {
$location.path('/bytag/' + $scope.query);
};

$scope.totalDocs = TotalFiles.get();
}


function UploadCtrl($scope, $http) {
$scope.uploadFiles = function() {
var form = $('form');
Expand Down
2 changes: 1 addition & 1 deletion app/partials/catalog.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h2>Institutos</h2>
<div id="cat-etiquetas">
<h2>Etiquetas</h2>
<span ng-repeat="tag in allTags.tags">
<a>{{tag}}</a>
<a href="#/bytag/{{tag}}">{{tag}}</a>
</span>
</div> <!-- end cat-etiquetas -->
</div> <!-- end content -->
14 changes: 14 additions & 0 deletions serverside/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,17 @@ def search(q):
msg['url'] = "docs/" + result['path']
out.append(msg)
return json.dumps(out)

def search_by_tag(q):
out = []
ix = whoosh.index.open_dir(INDEXDIR)
with ix.searcher() as searcher:
query = QueryParser("tags", ix.schema).parse(q)
results = searcher.search(query)
for result in results:
msg = {}
msg['title'] = result['title']
msg['tags'] = result['tags'].split(',')
msg['url'] = "docs/" + result['path']
out.append(msg)
return json.dumps(out)
7 changes: 7 additions & 0 deletions serverside/urldispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,11 @@ def docs(fn):
@route('/buscar/<q>')
def buscar(q):
response.set_header('Cache-Control', 'No-Cache')
response.set_header("Content-Type", "application/json")
return search.search(q)

@route('/etiqueta/<tag>')
def buscar_etiqueta(tag):
response.set_header('Cache-Control', 'No-Cache')
response.set_header("Content-Type", "application/json")
return search.search_by_tag(tag)

0 comments on commit 9823253

Please sign in to comment.