Skip to content

Commit

Permalink
add adv search
Browse files Browse the repository at this point in the history
  • Loading branch information
Jicheng Lu committed Sep 19, 2024
1 parent d9f4038 commit 691fcef
Show file tree
Hide file tree
Showing 11 changed files with 345 additions and 107 deletions.
3 changes: 2 additions & 1 deletion src/lib/helpers/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ const knowledgePayloadName = {
DataSource: 'dataSource',
FileId: 'fileId',
FileName: 'fileName',
FileSource: 'fileSource'
FileSource: 'fileSource',
FileUrl: 'fileUrl'
};
export const KnowledgePayloadName = Object.freeze(knowledgePayloadName);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function skipLoader(config) {
new RegExp('http(s*)://(.*?)/knowledge/vector/(.*?)/page', 'g'),
new RegExp('http(s*)://(.*?)/knowledge/(.*?)/search', 'g'),
new RegExp('http(s*)://(.*?)/knowledge/vector/(.*?)/create', 'g'),
new RegExp('http(s*)://(.*?)/knowledge/document/(.*?)/list', 'g')
new RegExp('http(s*)://(.*?)/knowledge/document/(.*?)/page', 'g')
];

const putRegexes = [
Expand Down
63 changes: 62 additions & 1 deletion src/lib/scss/custom/pages/_knowledgebase.scss
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@
white-space: wrap !important;
}

.more-detail-item {
.link {
color: var(--bs-primary);

&:hover {
text-decoration: underline;
}
}
}

.more-detail {
margin: 2px 0px;
padding-left: 2rem;
Expand Down Expand Up @@ -297,4 +307,55 @@
border-radius: 10px;
padding: 10px;
background-color: var(--bs-light);
}
}

.knowledge-adv-search-container {
.knowledge-adv-search-btn {
display: flex;
justify-content: flex-start;
gap: 10px;
font-size: 18px;

input {
outline: none !important;
box-shadow: none !important;
}
}

.knowledge-adv-search-items {
margin-top: 15px;
display: flex;
flex-direction: column;
gap: 10px;

.knowledge-adv-search-item {
display: flex;
gap: 10px;

.search-item-cb {
flex: 0 0 20px;

.form-check {
font-size: 15px;
margin-bottom: 0.125rem;
}

input[type="checkbox"] {
outline: none !important;
box-shadow: none !important;
}
}

.search-item-name {
font-size: 15px;
flex: 0 0 100px;
}

.search-item-content {
flex: 0.3;
min-width: 150px;
max-width: 350px;
}
}
}
}
4 changes: 2 additions & 2 deletions src/lib/services/api-endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const endpoints = {

// knowledge base
vectorKnowledgeCollectionsUrl: `${host}/knowledge/vector/collections`,
vectorKnowledgePageDataUrl: `${host}/knowledge/vector/{collection}/page`,
vectorKnowledgePageListUrl: `${host}/knowledge/vector/{collection}/page`,
vectorKnowledgeSearchUrl: `${host}/knowledge/vector/{collection}/search`,
vectorKnowledgeCreateUrl: `${host}/knowledge/vector/{collection}/create`,
vectorKnowledgeUpdateUrl: `${host}/knowledge/vector/{collection}/update`,
Expand All @@ -74,7 +74,7 @@ export const endpoints = {

knowledgeDocumentUploadUrl: `${host}/knowledge/document/{collection}/upload`,
knowledgeDocumentDeleteUrl: `${host}/knowledge/document/{collection}/delete/{fileId}`,
knowledgeDocumentListUrl: `${host}/knowledge/document/{collection}/list`,
knowledgeDocumentPageListUrl: `${host}/knowledge/document/{collection}/page`,

// chathub
chatHubUrl: `${host}/chatHub`,
Expand Down
18 changes: 9 additions & 9 deletions src/lib/services/knowledge-base-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export async function getVectorKnowledgeCollections(type) {
}

/**
* @param {import('$knowledgeTypes').SearchKnowledgeRequest} request
* @param {string} collection
* @param {import('$knowledgeTypes').SearchKnowledgeRequest} request
* @returns {Promise<import('$knowledgeTypes').KnowledgeSearchViewModel[]>}
*/
export async function searchVectorKnowledge(request, collection) {
export async function searchVectorKnowledge(collection, request) {
const url = replaceUrl(endpoints.vectorKnowledgeSearchUrl, {
collection: collection
});
Expand All @@ -31,12 +31,12 @@ export async function searchVectorKnowledge(request, collection) {
}

/**
* @param {import('$knowledgeTypes').KnowledgeFilter} filter
* @param {string} collection
* @param {import('$knowledgeTypes').KnowledgeFilter} filter
* @returns {Promise<import('$knowledgeTypes').KnowledgeSearchPageResult>}
*/
export async function getPagedVectorKnowledgeData(filter, collection) {
const url = replaceUrl(endpoints.vectorKnowledgePageDataUrl, {
export async function getVectorKnowledgePageList(collection, filter) {
const url = replaceUrl(endpoints.vectorKnowledgePageListUrl, {
collection: collection
});

Expand Down Expand Up @@ -96,11 +96,11 @@ export async function updateVectorKnowledgeData(id, collection, text, dataSource


/**
* @param {string} id
* @param {string} collection
* @param {string} id
* @returns {Promise<boolean>}
*/
export async function deleteVectorKnowledgeData(id, collection) {
export async function deleteVectorKnowledgeData(collection, id) {
const url = replaceUrl(endpoints.vectorKnowledgeDeleteUrl, {
collection: collection,
id: id
Expand Down Expand Up @@ -160,8 +160,8 @@ export async function deleteKnowledgeDocument(collection, fileId) {
* @param {import('$knowledgeTypes').KnowledgeDocRequest} request
* @returns {Promise<import('$knowledgeTypes').KnowledgeDocPagedResult>}
*/
export async function getKnowledgeDocuments(collection, request) {
const url = replaceUrl(endpoints.knowledgeDocumentListUrl, {
export async function getKnowledgeDocumentPageList(collection, request) {
const url = replaceUrl(endpoints.knowledgeDocumentPageListUrl, {
collection: collection
});

Expand Down
148 changes: 148 additions & 0 deletions src/routes/page/knowledge-base/common/search/advanced-search.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<script>
import { onMount, onDestroy } from 'svelte';
import { fly } from 'svelte/transition';
import { Input, Tooltip } from '@sveltestrap/sveltestrap';
import util from "lodash";
const maxLength = 50;
/** @type {{ key: string, displayName: string }[]} */
export let items;
/** @type {boolean} */
export let disabled = false;
/** @type {boolean} */
let showAdvSearch = false;
/** @type {any[]} */
let innerItems = [];
onMount(() => {
init();
});
onDestroy(() => {
reset();
});
function init() {
showAdvSearch = false;
reset();
}
/** @param {any} e */
function toggleAdvSearch(e) {
showAdvSearch = e.target.checked;
if (!showAdvSearch) {
reset();
}
}
function reset() {
innerItems = items?.map(x => {
return {
key: x.key,
checked: false,
displayName: x.displayName,
value: ''
};
}) || [];
}
/**
* @param {number} idx
* @param {any} e
*/
function toggleItemCheckbox(idx, e) {
const found = innerItems.find((_, index) => index === idx);
if (found) {
found.checked = e.target.checked;
innerItems = innerItems.map((x, index) => {
return index === idx ? { ...found } : x;
});
}
}
/**
* @param {number} idx
* @param {any} e
*/
function changeItemValue(idx, e) {
const found = innerItems.find((_, index) => index === idx);
if (found) {
found.value = e.target.value;
innerItems = innerItems.map((x, index) => {
return index === idx ? { ...found } : x;
});
}
}
</script>
<div
class="knowledge-adv-search-container"
in:fly={{ y: -10, duration: 500 }}
out:fly={{ y: -10, duration: 200 }}
>
<div class="knowledge-adv-search-btn text-primary fw-bold">
<Input
type="switch"
disabled={disabled}
checked={showAdvSearch}
on:change={e => toggleAdvSearch(e)}
/>
<div class="line-align-center">
<div>{'Advance Search'}</div>
</div>
{#if showAdvSearch}
<div class="line-align-center" id="adv-search-tooltip">
<i class="bx bx-info-circle" />
</div>
<Tooltip target="adv-search-tooltip" placement="top" class="demo-tooltip-note">
<ul>
<li>{'Select the checkbox to enable seaching in each field.'}</li>
<li>{'Empty value will not be used to search.'}</li>
</ul>
</Tooltip>
{/if}
</div>
{#if showAdvSearch}
<div
class={'knowledge-adv-search-items'}
in:fly={{ y: -10, duration: 500 }}
out:fly={{ y: -10, duration: 200 }}
>
{#each innerItems as item, idx (idx)}
<div class="knowledge-adv-search-item">
<div class="search-item-cb line-align-center">
<Input
type="checkbox"
disabled={disabled}
checked={item.checked}
on:change={e => toggleItemCheckbox(idx, e)}
/>
</div>
<div class="search-item-name fw-bold line-align-center">
<div>{`${item.displayName}:`}</div>
</div>
<div class="search-item-content line-align-center">
<Input
type="text"
disabled={!item.checked || disabled}
maxlength={maxLength}
value={item.value}
on:input={e => changeItemValue(idx, e)}
/>
</div>
</div>
{/each}
</div>
{/if}
</div>
Loading

0 comments on commit 691fcef

Please sign in to comment.