frontend support for fulltext sorting

This commit is contained in:
jonaswinkler 2021-05-15 18:48:39 +02:00
parent f3703fc6e3
commit 96f4924911
5 changed files with 56 additions and 8 deletions

View File

@ -1889,6 +1889,14 @@
<context context-type="linenumber">23</context>
</context-group>
</trans-unit>
<trans-unit id="4460262093225954455" datatype="html">
<source>Search score</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/services/rest/document.service.ts</context>
<context context-type="linenumber">28</context>
</context-group>
<note priority="1" from="description">Score is a value returned by the full text search engine and specifies how well a result matches the given query</note>
</trans-unit>
<trans-unit id="4561076822163447092" datatype="html">
<source>Create new item</source>
<context-group purpose="location">

View File

@ -2,14 +2,14 @@ import { Component, OnDestroy, OnInit, QueryList, ViewChild, ViewChildren } from
import { ActivatedRoute, Router } from '@angular/router';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { Subscription } from 'rxjs';
import { FilterRule } from 'src/app/data/filter-rule';
import { FilterRule, isFullTextFilterRule } from 'src/app/data/filter-rule';
import { FILTER_FULLTEXT_MORELIKE } from 'src/app/data/filter-rule-type';
import { PaperlessDocument } from 'src/app/data/paperless-document';
import { PaperlessSavedView } from 'src/app/data/paperless-saved-view';
import { SortableDirective, SortEvent } from 'src/app/directives/sortable.directive';
import { ConsumerStatusService } from 'src/app/services/consumer-status.service';
import { DocumentListViewService } from 'src/app/services/document-list-view.service';
import { DOCUMENT_SORT_FIELDS } from 'src/app/services/rest/document.service';
import { DOCUMENT_SORT_FIELDS, DOCUMENT_SORT_FIELDS_FULLTEXT } from 'src/app/services/rest/document.service';
import { SavedViewService } from 'src/app/services/rest/saved-view.service';
import { ToastService } from 'src/app/services/toast.service';
import { FilterEditorComponent } from './filter-editor/filter-editor.component';
@ -52,7 +52,7 @@ export class DocumentListComponent implements OnInit, OnDestroy {
}
getSortFields() {
return DOCUMENT_SORT_FIELDS
return isFullTextFilterRule(this.list.filterRules) ? DOCUMENT_SORT_FIELDS_FULLTEXT : DOCUMENT_SORT_FIELDS
}
onSort(event: SortEvent) {

View File

@ -1,3 +1,5 @@
import { FILTER_FULLTEXT_MORELIKE, FILTER_FULLTEXT_QUERY } from "./filter-rule-type"
export function cloneFilterRules(filterRules: FilterRule[]): FilterRule[] {
if (filterRules) {
let newRules: FilterRule[] = []
@ -10,6 +12,10 @@ export function cloneFilterRules(filterRules: FilterRule[]): FilterRule[] {
}
}
export function isFullTextFilterRule(filterRules: FilterRule[]): boolean {
return filterRules.find(r => r.rule_type == FILTER_FULLTEXT_QUERY || r.rule_type == FILTER_FULLTEXT_MORELIKE) != null
}
export interface FilterRule {
rule_type: number
value: string

View File

@ -1,28 +1,53 @@
import { Injectable } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { cloneFilterRules, FilterRule } from '../data/filter-rule';
import { FILTER_FULLTEXT_MORELIKE, FILTER_FULLTEXT_QUERY } from '../data/filter-rule-type';
import { cloneFilterRules, FilterRule, isFullTextFilterRule } from '../data/filter-rule';
import { PaperlessDocument } from '../data/paperless-document';
import { PaperlessSavedView } from '../data/paperless-saved-view';
import { DOCUMENT_LIST_SERVICE } from '../data/storage-keys';
import { DocumentService } from './rest/document.service';
import { SettingsService, SETTINGS_KEYS } from './settings.service';
/**
* Captures the current state of the list view.
*/
interface ListViewState {
/**
* Title of the document list view. Either "Documents" (localized) or the name of a saved view.
*/
title?: string
/**
* Current paginated list of documents displayed.
*/
documents?: PaperlessDocument[]
currentPage: number
/**
* Total amount of documents with the current filter rules. Used to calculate the number of pages.
*/
collectionSize: number
/**
* Currently selected sort field.
*/
sortField: string
/**
* True if the list is sorted in reverse.
*/
sortReverse: boolean
/**
* Filter rules for the current list view.
*/
filterRules: FilterRule[]
/**
* Contains the IDs of all selected documents.
*/
selected?: Set<number>
}
@ -134,10 +159,10 @@ export class DocumentListViewService {
}
set filterRules(filterRules: FilterRule[]) {
this.activeListViewState.filterRules = filterRules
if (filterRules.find(r => (r.rule_type == FILTER_FULLTEXT_QUERY || r.rule_type == FILTER_FULLTEXT_MORELIKE))) {
this.activeListViewState.currentPage = 1
if (!isFullTextFilterRule(filterRules) && this.activeListViewState.sortField == "score") {
this.activeListViewState.sortField = "created"
}
this.activeListViewState.filterRules = filterRules
this.reload()
this.reduceSelectionToFilter()
this.saveDocumentListView()
@ -213,6 +238,10 @@ export class DocumentListViewService {
this._activeSavedViewId = null
this.activeListViewState.filterRules = filterRules
this.activeListViewState.currentPage = 1
if (isFullTextFilterRule(filterRules)) {
this.activeListViewState.sortField = "score"
this.activeListViewState.sortReverse = false
}
this.reduceSelectionToFilter()
this.saveDocumentListView()
if (this.router.url == "/documents") {

View File

@ -23,6 +23,11 @@ export const DOCUMENT_SORT_FIELDS = [
{ field: 'modified', name: $localize`Modified` }
]
export const DOCUMENT_SORT_FIELDS_FULLTEXT = [
...DOCUMENT_SORT_FIELDS,
{ field: 'score', name: $localize`:Score is a value returned by the full text search engine and specifies how well a result matches the given query:Search score` }
]
export interface SelectionDataItem {
id: number
document_count: number