gitlabhq/gitlabhq — pull request #7612 by bushong1 (2014-08-26 22:13:09+00:00)
Title: Adding snippet search capability

In reference to this merge request:

http://feedback.gitlab.com/forums/176466-general/suggestions/5529795-search-though-snippets

##### What does this MR do?
Adds the capability to search snippets. This can be accessed whenever viewing a snippet related page, such as personal snippets, snippet discovery, and search snippets. There is a tab for searching just filenames and titles, and there is a tab for searching just the code of the snippet. It searches all public snippets, as well as the private snippets of the user.

##### Are there points in the code the reviewer needs to double check?
The biggest change is the creation of `snippet_service.rb` in `app/services/search/snippet_service.rb`. One thing I was unsure of was if there is any specific limit on how many snippet results should be returned in total from the query. I didn't want to leave it unlimited, as a user could search for a single character and potentially slow down the system. I put the limit at an arbitrary 500, paginating at 20 for the user, but someone may want to make a judgement call.

##### Why was this MR needed?
This is something my users have been asking for, and it should add a great amount of collaborative capability and global discovery to the snippets feature. In addition, there is a merge request already created with 9 points.

##### What are the relevant issue numbers / Feature requests?
http://feedback.gitlab.com/forums/176466-general/suggestions/5529795-search-though-snippets

##### Screenshots (If appropiate)

Image 1: Searching title/filename with no results.
![selection_005](https://cloud.githubusercontent.com/assets/236700/4052541/ddd3cdce-2d6c-11e4-8dc0-76502e5c4e85.png)

Image 2: Searching code with results.
![selection_006](https://cloud.githubusercontent.com/assets/236700/4052544/ddd7a912-2d6c-11e4-986a-a05a16f7a971.png)

Image 3: Searching title/filename with paginated results, first page. (the black bar towards the bottom is just ubuntu butting in while i maximize for a screenshot)
![selection_007](https://cloud.githubusercontent.com/assets/236700/4052539/ddd1b908-2d6c-11e4-8d78-490072a106a2.png)
Image 4: Searching title/filename with paginated results, second page.
![selection_008](https://cloud.githubusercontent.com/assets/236700/4052540/ddd35560-2d6c-11e4-9226-694da5dc4c4f.png)
Image 5: "Search Snippets" in search bar available on this page.
![selection_009](https://cloud.githubusercontent.com/assets/236700/4052542/ddd69072-2d6c-11e4-8a72-f8150877f4af.png)
Image 6: Searching in code will display text 3 lines before and 3 lines after any matches. It will collapse overlapping matches into one block.
![selection_010](https://cloud.githubusercontent.com/assets/236700/4052543/ddd6af62-2d6c-11e4-9b3c-4a3983389c70.png)