mirror of
https://github.com/documize/community.git
synced 2025-07-20 21:59:42 +02:00
Search history recording
1. Record all search queries. 2. Replaced typeahead with form style for faster search result fetch/rendering.
This commit is contained in:
parent
a6828e6b7f
commit
b4c4decb3b
4 changed files with 77 additions and 32 deletions
|
@ -17,6 +17,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/request"
|
"github.com/documize/community/core/request"
|
||||||
|
@ -394,6 +395,8 @@ func (h *Handler) SearchDocuments(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.Keywords = strings.TrimSpace(options.Keywords)
|
||||||
|
|
||||||
results, err := h.Store.Search.Documents(ctx, options)
|
results, err := h.Store.Search.Documents(ctx, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Runtime.Log.Error(method, err)
|
h.Runtime.Log.Error(method, err)
|
||||||
|
@ -406,16 +409,40 @@ func (h *Handler) SearchDocuments(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record user search history
|
// Record user search history
|
||||||
go h.recordSearchActivity(ctx, results)
|
if len(results) > 0 {
|
||||||
|
go h.recordSearchActivity(ctx, results, options.Keywords)
|
||||||
|
} else {
|
||||||
|
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||||
|
if err != nil {
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
|
LabelID: "",
|
||||||
|
DocumentID: "",
|
||||||
|
Metadata: options.Keywords,
|
||||||
|
SourceType: activity.SourceTypeSearch,
|
||||||
|
ActivityType: activity.TypeSearched})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
ctx.Transaction.Rollback()
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Transaction.Commit()
|
||||||
|
}
|
||||||
|
|
||||||
h.Store.Audit.Record(ctx, audit.EventTypeSearch)
|
h.Store.Audit.Record(ctx, audit.EventTypeSearch)
|
||||||
|
|
||||||
response.WriteJSON(w, results)
|
response.WriteJSON(w, results)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) recordSearchActivity(ctx domain.RequestContext, q []search.QueryResult) {
|
// Record search request once per document.
|
||||||
|
func (h *Handler) recordSearchActivity(ctx domain.RequestContext, q []search.QueryResult, keywords string) {
|
||||||
method := "recordSearchActivity"
|
method := "recordSearchActivity"
|
||||||
var err error
|
var err error
|
||||||
|
prev := make(map[string]bool)
|
||||||
|
|
||||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -424,9 +451,11 @@ func (h *Handler) recordSearchActivity(ctx domain.RequestContext, q []search.Que
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range q {
|
for i := range q {
|
||||||
|
if _, isExisting := prev[q[i].DocumentID]; !isExisting {
|
||||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: q[i].SpaceID,
|
LabelID: q[i].SpaceID,
|
||||||
DocumentID: q[i].DocumentID,
|
DocumentID: q[i].DocumentID,
|
||||||
|
Metadata: keywords,
|
||||||
SourceType: activity.SourceTypeSearch,
|
SourceType: activity.SourceTypeSearch,
|
||||||
ActivityType: activity.TypeSearched})
|
ActivityType: activity.TypeSearched})
|
||||||
|
|
||||||
|
@ -434,6 +463,10 @@ func (h *Handler) recordSearchActivity(ctx domain.RequestContext, q []search.Que
|
||||||
ctx.Transaction.Rollback()
|
ctx.Transaction.Rollback()
|
||||||
h.Runtime.Log.Error(method, err)
|
h.Runtime.Log.Error(method, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prev[q[i].DocumentID] = true
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Transaction.Commit()
|
ctx.Transaction.Commit()
|
||||||
|
|
|
@ -13,6 +13,13 @@ import Route from '@ember/routing/route';
|
||||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||||
|
|
||||||
export default Route.extend(AuthenticatedRouteMixin, {
|
export default Route.extend(AuthenticatedRouteMixin, {
|
||||||
|
queryParams: {
|
||||||
|
filter: {
|
||||||
|
replace: true,
|
||||||
|
refreshModel: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
activate() {
|
activate() {
|
||||||
this.get('browser').setTitle('Search');
|
this.get('browser').setTitle('Search');
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="view-search mt-5">
|
<div class="view-search mt-5">
|
||||||
<div class="heading">Search</div>
|
<div class="heading">Search</div>
|
||||||
|
<form onsubmit={{action 'onSearch'}}>
|
||||||
<div class="form-group mt-4">
|
<div class="form-group mt-4">
|
||||||
{{focus-input type="text" value=filter class="form-control mb-4" placeholder='a OR b, x AND y, "phrase mat*"'}}
|
{{focus-input type="text" value=filter class="form-control mb-4" placeholder='a OR b, x AND y, "phrase mat*"'}}
|
||||||
<div class="form-check form-check-inline">
|
<div class="form-check form-check-inline">
|
||||||
|
@ -30,6 +31,10 @@
|
||||||
<label class="form-check-label" for="search-4"> attachment name</label>
|
<label class="form-check-label" for="search-4"> attachment name</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<button class="btn btn-success" {{action 'onSearch'}}>Search</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
{{search/search-results results=results}}
|
{{search/search-results results=results}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<ul class="documents">
|
<ul class="documents">
|
||||||
{{#each documents key="id" as |result index|}}
|
{{#each documents key="id" as |result index|}}
|
||||||
<li class="document">
|
<li class="document">
|
||||||
<a class="link" href="s/{{result.spaceId}}/{{result.spaceSlug}}/d/{{ result.documentId }}/{{result.documentSlug}}?page={{ result.itemId }}">
|
<a class="link" href="s/{{result.spaceId}}/{{result.spaceSlug}}/d/{{ result.documentId }}/{{result.documentSlug}}?currentPageId={{result.itemId}}">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
{{result.document}}
|
{{result.document}}
|
||||||
{{#if (gt result.versionId.length 0)}}
|
{{#if (gt result.versionId.length 0)}}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue