Allow disabling advanced search in global search
This commit is contained in:
parent
00cfea7f4e
commit
8d7ee4cb1a
@ -197,6 +197,14 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4 class="mt-4" i18n>Global search</h4>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="offset-md-3 col">
|
||||
<pngx-input-check i18n-title title="Search database only (do not include advanced search results)" formControlName="searchDbOnly"></pngx-input-check>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4 class="mt-4" i18n>Notes</h4>
|
||||
|
||||
<div class="row mb-3">
|
||||
|
@ -305,7 +305,7 @@ describe('SettingsComponent', () => {
|
||||
expect(toastErrorSpy).toHaveBeenCalled()
|
||||
expect(storeSpy).toHaveBeenCalled()
|
||||
expect(appearanceSettingsSpy).not.toHaveBeenCalled()
|
||||
expect(setSpy).toHaveBeenCalledTimes(25)
|
||||
expect(setSpy).toHaveBeenCalledTimes(26)
|
||||
|
||||
// succeed
|
||||
storeSpy.mockReturnValueOnce(of(true))
|
||||
|
@ -99,6 +99,7 @@ export class SettingsComponent
|
||||
defaultPermsEditUsers: new FormControl(null),
|
||||
defaultPermsEditGroups: new FormControl(null),
|
||||
documentEditingRemoveInboxTags: new FormControl(null),
|
||||
searchDbOnly: new FormControl(null),
|
||||
|
||||
notificationsConsumerNewDocument: new FormControl(null),
|
||||
notificationsConsumerSuccess: new FormControl(null),
|
||||
@ -299,6 +300,7 @@ export class SettingsComponent
|
||||
documentEditingRemoveInboxTags: this.settings.get(
|
||||
SETTINGS_KEYS.DOCUMENT_EDITING_REMOVE_INBOX_TAGS
|
||||
),
|
||||
searchDbOnly: this.settings.get(SETTINGS_KEYS.SEARCH_DB_ONLY),
|
||||
savedViews: {},
|
||||
}
|
||||
}
|
||||
@ -522,6 +524,10 @@ export class SettingsComponent
|
||||
SETTINGS_KEYS.DOCUMENT_EDITING_REMOVE_INBOX_TAGS,
|
||||
this.settingsForm.value.documentEditingRemoveInboxTags
|
||||
)
|
||||
this.settings.set(
|
||||
SETTINGS_KEYS.SEARCH_DB_ONLY,
|
||||
this.settingsForm.value.searchDbOnly
|
||||
)
|
||||
this.settings.setLanguage(this.settingsForm.value.displayLanguage)
|
||||
this.settings
|
||||
.storeSettings()
|
||||
|
@ -56,6 +56,7 @@ export const SETTINGS_KEYS = {
|
||||
DEFAULT_PERMS_EDIT_GROUPS: 'general-settings:permissions:default-edit-groups',
|
||||
DOCUMENT_EDITING_REMOVE_INBOX_TAGS:
|
||||
'general-settings:document-editing:remove-inbox-tags',
|
||||
SEARCH_DB_ONLY: 'general-settings:search:db-only',
|
||||
}
|
||||
|
||||
export const SETTINGS: UiSetting[] = [
|
||||
@ -219,4 +220,9 @@ export const SETTINGS: UiSetting[] = [
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
key: SETTINGS_KEYS.SEARCH_DB_ONLY,
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
]
|
||||
|
@ -6,10 +6,13 @@ import { Subscription } from 'rxjs'
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { SearchService } from './search.service'
|
||||
import { SettingsService } from '../settings.service'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
|
||||
let httpTestingController: HttpTestingController
|
||||
let service: SearchService
|
||||
let subscription: Subscription
|
||||
let settingsService: SettingsService
|
||||
const endpoint = 'search/autocomplete'
|
||||
|
||||
describe('SearchService', () => {
|
||||
@ -20,6 +23,7 @@ describe('SearchService', () => {
|
||||
})
|
||||
|
||||
httpTestingController = TestBed.inject(HttpTestingController)
|
||||
settingsService = TestBed.inject(SettingsService)
|
||||
service = TestBed.inject(SearchService)
|
||||
})
|
||||
|
||||
@ -36,4 +40,18 @@ describe('SearchService', () => {
|
||||
)
|
||||
expect(req.request.method).toEqual('GET')
|
||||
})
|
||||
|
||||
it('should call correct api endpoint on globalSearch', () => {
|
||||
const query = 'apple'
|
||||
service.globalSearch(query).subscribe()
|
||||
httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}search/?query=${query}`
|
||||
)
|
||||
|
||||
settingsService.set(SETTINGS_KEYS.SEARCH_DB_ONLY, true)
|
||||
subscription = service.globalSearch(query).subscribe()
|
||||
httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}search/?query=${query}&db_only=true`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
@ -13,6 +13,8 @@ import { StoragePath } from 'src/app/data/storage-path'
|
||||
import { Tag } from 'src/app/data/tag'
|
||||
import { User } from 'src/app/data/user'
|
||||
import { Workflow } from 'src/app/data/workflow'
|
||||
import { SettingsService } from '../settings.service'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
|
||||
export interface GlobalSearchResult {
|
||||
total: number
|
||||
@ -33,7 +35,10 @@ export interface GlobalSearchResult {
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class SearchService {
|
||||
constructor(private http: HttpClient) {}
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
private settingsService: SettingsService
|
||||
) {}
|
||||
|
||||
autocomplete(term: string): Observable<string[]> {
|
||||
return this.http.get<string[]>(
|
||||
@ -43,9 +48,13 @@ export class SearchService {
|
||||
}
|
||||
|
||||
globalSearch(query: string): Observable<GlobalSearchResult> {
|
||||
let params = new HttpParams().set('query', query)
|
||||
if (this.settingsService.get(SETTINGS_KEYS.SEARCH_DB_ONLY)) {
|
||||
params = params.set('db_only', true)
|
||||
}
|
||||
return this.http.get<GlobalSearchResult>(
|
||||
`${environment.apiBaseUrl}search/`,
|
||||
{ params: new HttpParams().set('query', query) }
|
||||
{ params }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1110,6 +1110,8 @@ class GlobalSearchView(PassUserMixin):
|
||||
elif len(query) < 3:
|
||||
return HttpResponseBadRequest("Query must be at least 3 characters")
|
||||
|
||||
db_only = request.query_params.get("db_only", False)
|
||||
|
||||
OBJECT_LIMIT = 3
|
||||
docs = []
|
||||
if request.user.has_perm("documents.view_document"):
|
||||
@ -1120,7 +1122,7 @@ class GlobalSearchView(PassUserMixin):
|
||||
)
|
||||
# First search by title
|
||||
docs = all_docs.filter(title__icontains=query)[:OBJECT_LIMIT]
|
||||
if len(docs) < OBJECT_LIMIT:
|
||||
if not db_only and len(docs) < OBJECT_LIMIT:
|
||||
# If we don't have enough results, search by content
|
||||
from documents import index
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user