mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-02 13:32:51 +00:00
Add new search-index route to web-ui
This commit is contained in:
parent
d5c9923a6d
commit
6846f2f46e
@ -45,6 +45,7 @@ module Api exposing
|
||||
, getTags
|
||||
, getUsers
|
||||
, itemDetail
|
||||
, itemIndexSearch
|
||||
, itemSearch
|
||||
, login
|
||||
, loginSession
|
||||
@ -104,6 +105,7 @@ import Api.Model.ImapSettings exposing (ImapSettings)
|
||||
import Api.Model.ImapSettingsList exposing (ImapSettingsList)
|
||||
import Api.Model.InviteResult exposing (InviteResult)
|
||||
import Api.Model.ItemDetail exposing (ItemDetail)
|
||||
import Api.Model.ItemFtsSearch exposing (ItemFtsSearch)
|
||||
import Api.Model.ItemInsights exposing (ItemInsights)
|
||||
import Api.Model.ItemLightList exposing (ItemLightList)
|
||||
import Api.Model.ItemProposals exposing (ItemProposals)
|
||||
@ -1092,6 +1094,20 @@ moveAttachmentBefore flags itemId data receive =
|
||||
}
|
||||
|
||||
|
||||
itemIndexSearch :
|
||||
Flags
|
||||
-> ItemFtsSearch
|
||||
-> (Result Http.Error ItemLightList -> msg)
|
||||
-> Cmd msg
|
||||
itemIndexSearch flags query receive =
|
||||
Http2.authPost
|
||||
{ url = flags.config.baseUrl ++ "/api/v1/sec/item/searchIndex"
|
||||
, account = getAccount flags
|
||||
, body = Http.jsonBody (Api.Model.ItemFtsSearch.encode query)
|
||||
, expect = Http.expectJson receive Api.Model.ItemLightList.decoder
|
||||
}
|
||||
|
||||
|
||||
itemSearch : Flags -> ItemSearch -> (Result Http.Error ItemLightList -> msg) -> Cmd msg
|
||||
itemSearch flags search receive =
|
||||
Http2.authPost
|
||||
|
@ -3,6 +3,7 @@ module Page.Home.Data exposing
|
||||
, Msg(..)
|
||||
, SearchType(..)
|
||||
, ViewMode(..)
|
||||
, defaultSearchType
|
||||
, doSearchCmd
|
||||
, init
|
||||
, itemNav
|
||||
@ -35,6 +36,7 @@ type alias Model =
|
||||
, throttle : Throttle Msg
|
||||
, searchTypeDropdown : Comp.FixedDropdown.Model SearchType
|
||||
, searchType : SearchType
|
||||
, contentOnlySearch : Maybe String
|
||||
}
|
||||
|
||||
|
||||
@ -47,13 +49,6 @@ init flags =
|
||||
|
||||
else
|
||||
[ BasicSearch ]
|
||||
|
||||
defaultSearchType =
|
||||
if flags.config.fullTextSearchEnabled then
|
||||
ContentSearch
|
||||
|
||||
else
|
||||
BasicSearch
|
||||
in
|
||||
{ searchMenuModel = Comp.SearchMenu.init
|
||||
, itemListModel = Comp.ItemCardList.init
|
||||
@ -67,10 +62,20 @@ init flags =
|
||||
, searchTypeDropdown =
|
||||
Comp.FixedDropdown.initMap searchTypeString
|
||||
searchTypeOptions
|
||||
, searchType = defaultSearchType
|
||||
, searchType = defaultSearchType flags
|
||||
, contentOnlySearch = Nothing
|
||||
}
|
||||
|
||||
|
||||
defaultSearchType : Flags -> SearchType
|
||||
defaultSearchType flags =
|
||||
if flags.config.fullTextSearchEnabled then
|
||||
ContentSearch
|
||||
|
||||
else
|
||||
BasicSearch
|
||||
|
||||
|
||||
type Msg
|
||||
= Init
|
||||
| SearchMenuMsg Comp.SearchMenu.Msg
|
||||
@ -85,6 +90,7 @@ type Msg
|
||||
| SetBasicSearch String
|
||||
| SearchTypeMsg (Comp.FixedDropdown.Msg SearchType)
|
||||
| KeyUpMsg (Maybe KeyCode)
|
||||
| SetContentOnly String
|
||||
|
||||
|
||||
type SearchType
|
||||
@ -127,6 +133,19 @@ itemNav id model =
|
||||
|
||||
doSearchCmd : Flags -> UiSettings -> Int -> Model -> Cmd Msg
|
||||
doSearchCmd flags settings offset model =
|
||||
case model.searchType of
|
||||
BasicSearch ->
|
||||
doSearchDefaultCmd flags settings offset model
|
||||
|
||||
ContentSearch ->
|
||||
doSearchDefaultCmd flags settings offset model
|
||||
|
||||
ContentOnlySearch ->
|
||||
doSearchIndexCmd flags settings offset model
|
||||
|
||||
|
||||
doSearchDefaultCmd : Flags -> UiSettings -> Int -> Model -> Cmd Msg
|
||||
doSearchDefaultCmd flags settings offset model =
|
||||
let
|
||||
smask =
|
||||
Comp.SearchMenu.getItemSearch model.searchMenuModel
|
||||
@ -144,6 +163,27 @@ doSearchCmd flags settings offset model =
|
||||
Api.itemSearch flags mask ItemSearchAddResp
|
||||
|
||||
|
||||
doSearchIndexCmd : Flags -> UiSettings -> Int -> Model -> Cmd Msg
|
||||
doSearchIndexCmd flags settings offset model =
|
||||
case model.contentOnlySearch of
|
||||
Just q ->
|
||||
let
|
||||
mask =
|
||||
{ query = q
|
||||
, limit = settings.itemSearchPageSize
|
||||
, offset = offset
|
||||
}
|
||||
in
|
||||
if offset == 0 then
|
||||
Api.itemIndexSearch flags mask ItemSearchResp
|
||||
|
||||
else
|
||||
Api.itemIndexSearch flags mask ItemSearchAddResp
|
||||
|
||||
Nothing ->
|
||||
Cmd.none
|
||||
|
||||
|
||||
resultsBelowLimit : UiSettings -> Model -> Bool
|
||||
resultsBelowLimit settings model =
|
||||
let
|
||||
|
@ -11,6 +11,7 @@ import Page.Home.Data exposing (..)
|
||||
import Throttle
|
||||
import Time
|
||||
import Util.Html exposing (KeyCode(..))
|
||||
import Util.Maybe
|
||||
import Util.Update
|
||||
|
||||
|
||||
@ -27,7 +28,10 @@ update key flags settings msg model =
|
||||
ResetSearch ->
|
||||
let
|
||||
nm =
|
||||
{ model | searchOffset = 0 }
|
||||
{ model
|
||||
| searchOffset = 0
|
||||
, searchType = defaultSearchType flags
|
||||
}
|
||||
in
|
||||
update key flags settings (SearchMenuMsg Comp.SearchMenu.ResetForm) nm
|
||||
|
||||
@ -161,10 +165,16 @@ update key flags settings msg model =
|
||||
SearchMenuMsg (Comp.SearchMenu.SetFulltext str)
|
||||
|
||||
ContentOnlySearch ->
|
||||
Debug.todo "implement"
|
||||
SetContentOnly str
|
||||
in
|
||||
update key flags settings smMsg model
|
||||
|
||||
SetContentOnly str ->
|
||||
withSub
|
||||
( { model | contentOnlySearch = Util.Maybe.fromString str }
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
SearchTypeMsg lm ->
|
||||
let
|
||||
( sm, mv ) =
|
||||
|
@ -134,7 +134,7 @@ viewSearchBar flags model =
|
||||
model.searchMenuModel.fulltextModel
|
||||
|
||||
ContentOnlySearch ->
|
||||
Debug.todo "implement"
|
||||
model.contentOnlySearch
|
||||
|
||||
searchTypeClass =
|
||||
if flags.config.fullTextSearchEnabled then
|
||||
@ -211,6 +211,6 @@ hasMoreSearch model =
|
||||
{ is | fullText = Nothing }
|
||||
|
||||
ContentOnlySearch ->
|
||||
Debug.todo "implement"
|
||||
Api.Model.ItemSearch.empty
|
||||
in
|
||||
is_ /= Api.Model.ItemSearch.empty
|
||||
|
Loading…
x
Reference in New Issue
Block a user