Skip to content

Commit

Permalink
Various updates to search. Now base64 encoding all query params when …
Browse files Browse the repository at this point in the history
…searching.
  • Loading branch information
Jeremy Sik committed Oct 1, 2015
1 parent b730079 commit e687707
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 17 deletions.
4 changes: 2 additions & 2 deletions api/app/Http/Controllers/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getAllPaginated(Request $request, RangeRequest $rangeRequest)
$offset = $rangeRequest->isGetLast() ? $totalCount - $limit : $rangeRequest->getOffset();

if ($request->has('q')) {
$collection = $this->searchAllEntities($request->query('q'), $limit, $offset, $totalCount);
$collection = $this->searchAllEntities(base64_decode($request->query('q')), $limit, $offset, $totalCount);
} else {
$collection = $this->getAllEntities($limit, $offset);
}
Expand Down Expand Up @@ -293,7 +293,7 @@ protected function getAllEntities($limit = null, $offset = null)
}

/**
* @param $queryString
* @param $query
* @param null $limit
* @param null $offset
* @param null $totalCount
Expand Down
2 changes: 1 addition & 1 deletion api/config/elasticquent.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
| Elastiquent models.
*/

'default_index' => 'sprout',
'default_index' => 'spira',

];
22 changes: 17 additions & 5 deletions api/tests/integration/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function testGetAllPaginatedSimpleSearch()

$this->app->instance(TestEntity::class, $mockModel);

$this->getJson('/test/entities/pages?q=foobar', ['Range' => 'entities=0-']);
$this->getJson('/test/entities/pages?q=' . base64_encode('foobar'), ['Range' => 'entities=0-']);

$this->assertResponseStatus(404);
}
Expand Down Expand Up @@ -201,7 +201,15 @@ public function testGetAllPaginatedComplexSearch()

$this->app->instance(TestEntity::class, $mockModel);

$this->getJson('/test/entities/pages?q=%7B%22_all%22%3A%5B%22search%20term%22%5D%2C%22authorId%22%3A%5B%22some%20UUID%22%5D%2C%22_tags%22%3A%7B%22tagId%22%3A%5B%22tag%20ID%201%22%2C%20%22tag%20ID%202%22%5D%7D%7D', ['Range' => 'entities=0-']);
$query = [
'_all' => ['search term'],
'authorId' => ['some UUID'],
'_tags'=> ['tagId' =>
['tag ID 1', 'tag ID 2']
]
];

$this->getJson('/test/entities/pages?q=' . base64_encode(json_encode($query)), ['Range' => 'entities=0-']);

$this->assertResponseStatus(404);
}
Expand Down Expand Up @@ -233,7 +241,11 @@ public function testGetAllPaginatedComplexSearchMatchAll()

$this->app->instance(TestEntity::class, $mockModel);

$this->getJson('/test/entities/pages?q=%7B%22authorId%22%3A%5B%22%22%5D%7D', ['Range' => 'entities=0-']);
$query = [
'authorId' => ['']
];

$this->getJson('/test/entities/pages?q=' . base64_encode(json_encode($query)), ['Range' => 'entities=0-']);

$this->assertResponseStatus(206);
}
Expand Down Expand Up @@ -723,7 +735,7 @@ public function testEntitySearch()

sleep(1); //give the elastic search agent time to index

$this->getJson('/test/entities/pages?q=searchforthisstring', ['Range' => 'entities=0-9']);
$this->getJson('/test/entities/pages?q=' . base64_encode('searchforthisstring'), ['Range' => 'entities=0-9']);

$collection = json_decode($this->response->getContent());
$this->assertResponseStatus(206);
Expand All @@ -737,7 +749,7 @@ public function testEntitySearch()

public function testEntitySearchNoResults()
{
$this->getJson('/test/entities/pages?q=thisstringwontreturnresults', ['Range' => 'entities=0-9']);
$this->getJson('/test/entities/pages?q=' . base64_encode('thisstringwontreturnresults'), ['Range' => 'entities=0-9']);

$this->assertResponseStatus(404);
$this->shouldReturnJson();
Expand Down
2 changes: 2 additions & 0 deletions app/src/app/admin/articles/listing/listing.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ <h2>Articles</h2>
</md-chips>
</md-content>

<div ng-if="ArticlesListingController.articles.length < 1"><h3>No articles found!</h3></div>

<md-grid-list
md-cols-sm="1"
md-cols-md="2"
Expand Down
5 changes: 4 additions & 1 deletion app/src/app/admin/articles/listing/listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ namespace app.admin.articles.listing {
.then((articles) => {
this.articles = articles;
})
.finally(() => { //@todo handle case where search returns no results
.catch(() => {
this.articles = [];
})
.finally(() => {
this.pages = this.articlesPaginator.getPages();
});
}
Expand Down
16 changes: 9 additions & 7 deletions app/src/common/services/pagination/paginationService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ interface mockEntity {

let paginator = paginationService.getPaginatorInstance('/collection').setCount(3);

$httpBackend.expectGET('/api/collection?q=foo%40bar.com', (headers) => {
$httpBackend.expectGET('/api/collection?q=' + btoa('foo@bar.com'), (headers) => {
return headers.Range == 'entities=0-2'
})
.respond(206, _.take(collection, 3));
Expand All @@ -400,15 +400,17 @@ interface mockEntity {

let paginator = paginationService.getPaginatorInstance('/collection').setCount(3);

$httpBackend.expectGET('/api/collection?q=%7B%22_all%22%3A%22foobar%22%2C%22entityId%22%3A%22foobarId%22%7D', (headers) => {
let query = {
_all:'foobar',
entityId:'foobarId'
};

$httpBackend.expectGET('/api/collection?q=' + btoa(angular.toJson(query)), (headers) => {
return headers.Range == 'entities=0-2'
})
.respond(206, _.take(collection, 3));

let results = paginator.complexQuery({
_all:'foobar',
entityId:'foobarId'
});
let results = paginator.complexQuery(query);

$httpBackend.flush();

Expand Down Expand Up @@ -437,7 +439,7 @@ interface mockEntity {

let paginator = paginationService.getPaginatorInstance('/collection').setCount(3);

$httpBackend.expectGET('/api/collection?q=findnothing', (headers) => {
$httpBackend.expectGET('/api/collection?q=' + btoa('findnothing'), (headers) => {
return headers.Range == 'entities=0-2'
})
.respond(404);
Expand Down
2 changes: 1 addition & 1 deletion app/src/common/services/pagination/paginationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace common.services.pagination {

let url = this.url;
if(!_.isEmpty(this.queryString)) {
url += '?q=' + (<any>this.$window).encodeURIComponent(this.queryString);
url += '?q=' + btoa(this.queryString);
}

return this.ngRestAdapter
Expand Down

0 comments on commit e687707

Please sign in to comment.