aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/search
diff options
context:
space:
mode:
authorEric <ericmabr@gmail.com>2023-08-13 16:08:28 -0400
committerEric <ericmabr@gmail.com>2023-08-13 16:08:28 -0400
commit0020ec69b847c8607affb57babddfddc812dc9b6 (patch)
treee24255039015745d2073806bee97ce449ddb5260 /src/client/views/search
parent7b2553514bb000eb7f618eb0f0d653baee78742c (diff)
parent3b45f1d30a947dc1702ec347b83e98374c5b603c (diff)
Merge branch 'master' into UI_Update_Eric_Ma
Diffstat (limited to 'src/client/views/search')
-rw-r--r--src/client/views/search/SearchBox.scss64
-rw-r--r--src/client/views/search/SearchBox.tsx84
2 files changed, 122 insertions, 26 deletions
diff --git a/src/client/views/search/SearchBox.scss b/src/client/views/search/SearchBox.scss
index e8865b918..a439aea3e 100644
--- a/src/client/views/search/SearchBox.scss
+++ b/src/client/views/search/SearchBox.scss
@@ -13,12 +13,16 @@
.searchBox-bar {
width: 100%;
- height: 35px;
+ height: fit-content;
display: flex;
justify-content: center;
align-items: center;
background-color: none;
padding: 5px;
+ top: 0px;
+ position: sticky;
+ overflow-y: scroll;
+ border-bottom: $standard-border;
.searchBox-type {
display: block;
@@ -42,34 +46,66 @@
}
}
- .searchBox-results-container {
+ .section-header {
+
+ .section-title {
+ font-size: $body-text;
+ font-weight: 600;
+ }
+
+ .section-subtitle {
+ display: flex;
+ color: $light-gray;
+ }
+
+ padding: 5px 10px;
+ display: flex;
+ flex-direction: column;
+ gap: 3px;
+ background: $medium-blue;
+ color: white;
+ }
+
+ .searchBox-recommendations-container {
display: flex;
flex-direction: column;
width: 100%;
- height: 100%;
+ height: fit-content;
justify-content: "center";
-
- .searchBox-results-count {
+
+ .searchBox-recommendations-view {
+ margin-top: 10px;
display: flex;
- color: gray;
- margin-left: 5px;
+ width: 100%;
+ height: fit-content;
+ flex-direction: column;
+ gap: 10px;
+ padding: 0px 10px;
+
+
}
+ }
+
+ .searchBox-results-container {
+ display: flex;
+ flex-direction: column;
+ width: 100%;
+ height: fit-content;
+ justify-content: "center";
- .searchBox-results-scroll-view {
- margin-top: 10px;
+ .searchBox-results-view {
display: inline-block;
width: 100%;
- height: calc(100% - 55px);
- overflow-y: scroll;
+ height: fit-content;
.searchBox-results-scroll-view-result {
display: inline-block;
vertical-align: middle;
width: 100%;
- height: 50px;
+ height: fit-content;
cursor: pointer;
font-size: 15px;
- padding: 11px;
+ padding: 10px;
&.searchBox-results-scroll-view-result-selected {
background: #999;
@@ -81,6 +117,8 @@
width: calc(100% - 45px);
text-align: left;
overflow: hidden;
+ max-height: 2.4em;
+ line-height: 1.2em;
text-overflow: ellipsis;
}
diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index 536ec7c75..1ceea697a 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -2,7 +2,8 @@ import { Tooltip } from '@material-ui/core';
import { action, computed, observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
-import { DirectLinksSym, Doc, DocListCast, DocListCastAsync, Field, Opt } from '../../../fields/Doc';
+import { Doc, DocListCast, DocListCastAsync, Field, Opt } from '../../../fields/Doc';
+import { DirectLinks } from '../../../fields/DocSymbols';
import { Id } from '../../../fields/FieldSymbols';
import { DocCast, StrCast } from '../../../fields/Types';
import { DocUtils } from '../../documents/Documents';
@@ -14,6 +15,10 @@ import { CollectionDockingView } from '../collections/CollectionDockingView';
import { ViewBoxBaseComponent } from '../DocComponent';
import { FieldView, FieldViewProps } from '../nodes/FieldView';
import './SearchBox.scss';
+import { fetchRecommendations } from '../newlightbox/utils';
+import { IRecommendation, Recommendation } from '../newlightbox/components';
+import { Colors } from '../global/globalEnums';
+import { SettingsManager } from '../../util/SettingsManager';
const DAMPENING_FACTOR = 0.9;
const MAX_ITERATIONS = 25;
@@ -42,6 +47,7 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
@observable _searchString = '';
@observable _docTypeString = 'all';
@observable _results: Map<Doc, string[]> = new Map<Doc, string[]>();
+ @observable _recommendations: IRecommendation[] = [];
@observable _pageRanks: Map<Doc, number> = new Map<Doc, number>();
@observable _linkedDocsOut: Map<Doc, Set<Doc>> = new Map<Doc, Set<Doc>>();
@observable _linkedDocsIn: Map<Doc, Set<Doc>> = new Map<Doc, Set<Doc>>();
@@ -141,6 +147,8 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
const annos = !Field.toString(Doc.LayoutField(d) as Field).includes('CollectionView');
const data = d[annos ? fieldKey + '_annotations' : fieldKey];
data && newarray.push(...DocListCast(data));
+ const sidebar = d[fieldKey + '_sidebar'];
+ sidebar && newarray.push(...DocListCast(sidebar));
func(depth, d);
});
docs = newarray;
@@ -211,7 +219,7 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
}
@action
static staticSearchCollection(rootDoc: Opt<Doc>, query: string) {
- const blockedTypes = [DocumentType.PRESELEMENT, DocumentType.MARKER, DocumentType.KVP, DocumentType.FILTER, DocumentType.SEARCH, DocumentType.SEARCHITEM, DocumentType.FONTICON, DocumentType.BUTTON, DocumentType.SCRIPTING];
+ const blockedTypes = [DocumentType.PRESELEMENT, DocumentType.CONFIG, DocumentType.KVP, DocumentType.SEARCH, DocumentType.FONTICON, DocumentType.BUTTON, DocumentType.SCRIPTING];
const blockedKeys = [
'x',
'y',
@@ -219,7 +227,7 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
'width',
'layout_autoHeight',
'acl-Override',
- 'acl-Public',
+ 'acl-Guest',
'embedContainer',
'zIndex',
'height',
@@ -240,7 +248,7 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
'layout',
'layout_keyValue',
'layout_fitWidth',
- 'viewType',
+ 'type_collection',
'title_custom',
'freeform_panX',
'freeform_panY',
@@ -290,7 +298,7 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
this._results.forEach((_, doc) => {
this._pageRanks.set(doc, 1.0 / this._results.size);
- if (Doc.GetProto(doc)[DirectLinksSym].size === 0) {
+ if (Doc.GetProto(doc)[DirectLinks].size === 0) {
this._linkedDocsOut.set(doc, new Set(this._results.keys()));
this._results.forEach((_, linkedDoc) => {
@@ -299,7 +307,7 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
} else {
const linkedDocSet = new Set<Doc>();
- Doc.GetProto(doc)[DirectLinksSym].forEach(link => {
+ Doc.GetProto(doc)[DirectLinks].forEach(link => {
const d1 = link?.link_anchor_1 as Doc;
const d2 = link?.link_anchor_2 as Doc;
if (doc === d1 && this._results.has(d2)) {
@@ -391,6 +399,37 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
if (query) {
this.searchCollection(query);
+ const response = await fetchRecommendations('', query, [], true);
+ const recs = response.recommendations;
+ const recommendations: IRecommendation[] = [];
+ for (const key in recs) {
+ const title = recs[key].title;
+ const url = recs[key].url;
+ const type = recs[key].type;
+ const text = recs[key].text;
+ const transcript = recs[key].transcript;
+ const previewUrl = recs[key].previewUrl;
+ const embedding = recs[key].embedding;
+ const distance = recs[key].distance;
+ const source = recs[key].source;
+ const related_concepts = recs[key].related_concepts;
+ const docId = recs[key].doc_id;
+ recommendations.push({
+ title: title,
+ data: url,
+ type: type,
+ text: text,
+ transcript: transcript,
+ previewUrl: previewUrl,
+ embedding: embedding,
+ distance: Math.round(distance * 100) / 100,
+ source: source,
+ related_concepts: related_concepts,
+ docId: docId,
+ });
+ }
+ const setRecommendations = action(() => (this._recommendations = recommendations));
+ setRecommendations();
}
};
@@ -400,6 +439,7 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
*/
resetSearch = action(() => {
this._results.forEach((_, doc) => {
+ DocumentManager.Instance.getFirstDocumentView(doc)?.ComponentView?.search?.('', undefined, true);
Doc.UnBrushDoc(doc);
Doc.UnHighlightDoc(doc);
Doc.ClearSearchMatches();
@@ -422,7 +462,7 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
*/
@computed
public get selectOptions() {
- const selectValues = ['all', 'rtf', 'image', 'pdf', 'web', 'video', 'audio', 'collection'];
+ const selectValues = ['all', DocumentType.RTF, DocumentType.IMG, DocumentType.PDF, DocumentType.WEB, DocumentType.VID, DocumentType.AUDIO, DocumentType.COL];
return selectValues.map(value => (
<option key={value} value={value}>
@@ -478,15 +518,19 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
className={className}>
<div className="searchBox-result-title">{title as string}</div>
<div className="searchBox-result-type">{formattedType}</div>
- <div className="searchBox-result-keys">{result[1].join(', ')}</div>
+ <div className="searchBox-result-keys" style={{ color: SettingsManager.Instance.userVariantColor }}>
+ {result[1].join(', ')}
+ </div>
</div>
</Tooltip>
);
}
});
+ const recommendationsJSX: JSX.Element[] = this._recommendations.map(props => <Recommendation {...props} />);
+
return (
- <div style={{ pointerEvents: 'all' }} className="searchBox-container">
+ <div className="searchBox-container" style={{ pointerEvents: 'all', color: SettingsManager.Instance.userColor, background: SettingsManager.Instance.userBackgroundColor }}>
<div className="searchBox-bar">
{isLinkSearch ? null : (
<select name="type" id="searchBox-type" className="searchBox-type" onChange={this.onSelectChange}>
@@ -509,10 +553,24 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
ref={this._inputRef}
/>
</div>
- <div className="searchBox-results-container">
- <div className="searchBox-results-count">{`${validResults}` + ' result' + (validResults === 1 ? '' : 's')}</div>
- <div className="searchBox-results-scroll-view">{resultsJSX}</div>
- </div>
+ {resultsJSX.length > 0 && (
+ <div className="searchBox-results-container">
+ <div className="section-header" style={{ background: StrCast(Doc.UserDoc().userVariantColor, Colors.MEDIUM_BLUE) }}>
+ <div className="section-title">Results</div>
+ <div className="section-subtitle">{`${validResults}` + ' result' + (validResults === 1 ? '' : 's')}</div>
+ </div>
+ <div className="searchBox-results-view">{resultsJSX}</div>
+ </div>
+ )}
+ {recommendationsJSX.length > 0 && (
+ <div className="searchBox-recommendations-container">
+ <div className="section-header" style={{ background: StrCast(Doc.UserDoc().userVariantColor, Colors.MEDIUM_BLUE) }}>
+ <div className="section-title">Recommendations</div>
+ <div className="section-subtitle">{`${validResults}` + ' result' + (validResults === 1 ? '' : 's')}</div>
+ </div>
+ <div className="searchBox-recommendations-view">{recommendationsJSX}</div>
+ </div>
+ )}
</div>
);
}