Run "Title & content" search from global search instead of advanced

- This is in line with the default for the "documents" view
  (such as after "Reset filters")
- It's more intuitive for new users
- It yields the most search results

Ref. paperless-ngx/paperless-ngx#6632
This commit is contained in:
Felix Eckhofer 2024-05-21 10:22:11 +02:00
parent 2a0c03eda0
commit 6897ffbd73
No known key found for this signature in database
GPG Key ID: B4543DCDE458BF73
3 changed files with 12 additions and 12 deletions

View File

@ -19,8 +19,8 @@
</div> </div>
</div> </div>
@if (query) { @if (query) {
<button class="btn btn-sm btn-outline-secondary" type="button" (click)="runAdvanedSearch()"> <button class="btn btn-sm btn-outline-secondary" type="button" (click)="runContentSearch()">
<ng-container i18n>Advanced search</ng-container> <ng-container i18n>Search contents</ng-container>
<i-bs width="1em" height="1em" name="arrow-right-short"></i-bs> <i-bs width="1em" height="1em" name="arrow-right-short"></i-bs>
</button> </button>
} }

View File

@ -20,11 +20,11 @@ import { DocumentListViewService } from 'src/app/services/document-list-view.ser
import { HttpClientTestingModule } from '@angular/common/http/testing' import { HttpClientTestingModule } from '@angular/common/http/testing'
import { FormsModule, ReactiveFormsModule } from '@angular/forms' import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { import {
FILTER_FULLTEXT_QUERY,
FILTER_HAS_CORRESPONDENT_ANY, FILTER_HAS_CORRESPONDENT_ANY,
FILTER_HAS_DOCUMENT_TYPE_ANY, FILTER_HAS_DOCUMENT_TYPE_ANY,
FILTER_HAS_STORAGE_PATH_ANY, FILTER_HAS_STORAGE_PATH_ANY,
FILTER_HAS_TAGS_ALL, FILTER_HAS_TAGS_ALL,
FILTER_TITLE_CONTENT,
} from 'src/app/data/filter-rule-type' } from 'src/app/data/filter-rule-type'
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons' import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
import { DocumentService } from 'src/app/services/rest/document.service' import { DocumentService } from 'src/app/services/rest/document.service'
@ -262,9 +262,9 @@ describe('GlobalSearchComponent', () => {
component.searchResults = searchResults as any component.searchResults = searchResults as any
component.resultsDropdown.open() component.resultsDropdown.open()
component.query = 'test' component.query = 'test'
const advancedSearchSpy = jest.spyOn(component, 'runAdvanedSearch') const contentsSearchSpy = jest.spyOn(component, 'runContentSearch')
component.searchInputKeyDown(new KeyboardEvent('keydown', { key: 'Enter' })) component.searchInputKeyDown(new KeyboardEvent('keydown', { key: 'Enter' }))
expect(advancedSearchSpy).toHaveBeenCalled() expect(contentsSearchSpy).toHaveBeenCalled()
}) })
it('should search on query debounce', fakeAsync(() => { it('should search on query debounce', fakeAsync(() => {
@ -499,12 +499,12 @@ describe('GlobalSearchComponent', () => {
expect(focusSpy).toHaveBeenCalled() expect(focusSpy).toHaveBeenCalled()
}) })
it('should support explicit advanced search', () => { it('should support explicit contents search', () => {
const qfSpy = jest.spyOn(documentListViewService, 'quickFilter') const qfSpy = jest.spyOn(documentListViewService, 'quickFilter')
component.query = 'test' component.query = 'test'
component.runAdvanedSearch() component.runContentSearch()
expect(qfSpy).toHaveBeenCalledWith([ expect(qfSpy).toHaveBeenCalledWith([
{ rule_type: FILTER_FULLTEXT_QUERY, value: 'test' }, { rule_type: FILTER_TITLE_CONTENT, value: 'test' },
]) ])
}) })

View File

@ -10,7 +10,7 @@ import { Router } from '@angular/router'
import { NgbDropdown, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap' import { NgbDropdown, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
import { Subject, debounceTime, distinctUntilChanged, filter, map } from 'rxjs' import { Subject, debounceTime, distinctUntilChanged, filter, map } from 'rxjs'
import { import {
FILTER_FULLTEXT_QUERY, FILTER_TITLE_CONTENT,
FILTER_HAS_CORRESPONDENT_ANY, FILTER_HAS_CORRESPONDENT_ANY,
FILTER_HAS_DOCUMENT_TYPE_ANY, FILTER_HAS_DOCUMENT_TYPE_ANY,
FILTER_HAS_STORAGE_PATH_ANY, FILTER_HAS_STORAGE_PATH_ANY,
@ -282,7 +282,7 @@ export class GlobalSearchComponent implements OnInit {
this.primaryButtons.first.nativeElement.click() this.primaryButtons.first.nativeElement.click()
this.searchInput.nativeElement.blur() this.searchInput.nativeElement.blur()
} else if (this.query?.length) { } else if (this.query?.length) {
this.runAdvanedSearch() this.runContentSearch()
this.reset(true) this.reset(true)
} }
} else if (event.key === 'Escape' && !this.resultsDropdown.isOpen()) { } else if (event.key === 'Escape' && !this.resultsDropdown.isOpen()) {
@ -378,9 +378,9 @@ export class GlobalSearchComponent implements OnInit {
) )
} }
public runAdvanedSearch() { public runContentSearch() {
this.documentListViewService.quickFilter([ this.documentListViewService.quickFilter([
{ rule_type: FILTER_FULLTEXT_QUERY, value: this.query }, { rule_type: FILTER_TITLE_CONTENT, value: this.query },
]) ])
this.reset(true) this.reset(true)
} }