mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-19 12:03:54 +02:00
Prevent spam search (#2367)
This commit is contained in:
@@ -2,7 +2,9 @@ import React, { KeyboardEvent, ChangeEvent, useContext } from "react";
|
||||
|
||||
import { MagnifyingGlass } from "@phosphor-icons/react";
|
||||
interface FullSearchBarProps {
|
||||
disabled: boolean;
|
||||
query: string;
|
||||
setPopup: (popupSpec: PopupSpec | null) => void;
|
||||
setQuery: (query: string) => void;
|
||||
onSearch: (fast?: boolean) => void;
|
||||
agentic?: boolean;
|
||||
@@ -14,6 +16,7 @@ interface FullSearchBarProps {
|
||||
finalAvailableSources: string[];
|
||||
tags: Tag[];
|
||||
showingSidebar: boolean;
|
||||
previousSearch: string;
|
||||
}
|
||||
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
@@ -25,6 +28,7 @@ import { SettingsContext } from "../settings/SettingsProvider";
|
||||
import { HorizontalSourceSelector, SourceSelector } from "./filtering/Filters";
|
||||
import { CCPairBasicInfo, DocumentSet, Tag } from "@/lib/types";
|
||||
import { SourceMetadata } from "@/lib/search/interfaces";
|
||||
import { PopupSpec } from "../admin/connectors/Popup";
|
||||
|
||||
export const AnimatedToggle = ({
|
||||
isOn,
|
||||
@@ -123,6 +127,7 @@ export const AnimatedToggle = ({
|
||||
export default AnimatedToggle;
|
||||
|
||||
export const FullSearchBar = ({
|
||||
disabled,
|
||||
showingSidebar,
|
||||
query,
|
||||
setQuery,
|
||||
@@ -133,8 +138,10 @@ export const FullSearchBar = ({
|
||||
documentSets,
|
||||
filterManager,
|
||||
finalAvailableDocumentSets,
|
||||
setPopup,
|
||||
finalAvailableSources,
|
||||
tags,
|
||||
previousSearch,
|
||||
}: FullSearchBarProps) => {
|
||||
const handleChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const target = event.target;
|
||||
@@ -152,8 +159,10 @@ export const FullSearchBar = ({
|
||||
!event.shiftKey &&
|
||||
!(event.nativeEvent as any).isComposing
|
||||
) {
|
||||
onSearch(agentic);
|
||||
event.preventDefault();
|
||||
if (!disabled) {
|
||||
onSearch(agentic);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -200,13 +209,12 @@ export const FullSearchBar = ({
|
||||
style={{ scrollbarWidth: "thin" }}
|
||||
role="textarea"
|
||||
aria-multiline
|
||||
placeholder="Search for something..."
|
||||
placeholder="Search for anything..."
|
||||
value={query}
|
||||
onChange={handleChange}
|
||||
onKeyDown={(event) => {}}
|
||||
suppressContentEditableWarning={true}
|
||||
/>
|
||||
|
||||
<div
|
||||
className={`flex ${showingSidebar ? " 2xl:justify-between" : "2xl:justify-end"} justify-between 4xl:justify-end w-full items-center space-x-3 py-3 px-4`}
|
||||
>
|
||||
@@ -226,9 +234,9 @@ export const FullSearchBar = ({
|
||||
{toggleAgentic && (
|
||||
<AnimatedToggle isOn={agentic!} handleToggle={toggleAgentic} />
|
||||
)}
|
||||
|
||||
<div className="my-auto pl-2">
|
||||
<button
|
||||
disabled={disabled}
|
||||
onClick={() => {
|
||||
onSearch(agentic);
|
||||
}}
|
||||
@@ -236,7 +244,7 @@ export const FullSearchBar = ({
|
||||
>
|
||||
<SendIcon
|
||||
size={28}
|
||||
className={`text-emphasis text-white p-1 rounded-full ${
|
||||
className={`text-emphasis ${disabled && "opacity-50"} text-white p-1 rounded-full ${
|
||||
query ? "bg-background-800" : "bg-[#D7D7D7]"
|
||||
}`}
|
||||
/>
|
||||
|
@@ -169,7 +169,10 @@ export const SearchResultsDisplay = ({
|
||||
<p>Results</p>
|
||||
{!DISABLE_LLM_DOC_RELEVANCE &&
|
||||
(contentEnriched || searchResponse.additional_relevance) && (
|
||||
<Tooltip delayDuration={1000} content={`${commandSymbol}O`}>
|
||||
<Tooltip
|
||||
delayDuration={1000}
|
||||
content={<div className="flex">{commandSymbol}O</div>}
|
||||
>
|
||||
<button
|
||||
onClick={() => {
|
||||
performSweep();
|
||||
|
@@ -1,10 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import { useContext, useEffect, useRef, useState } from "react";
|
||||
import { FullSearchBar } from "./SearchBar";
|
||||
import { FullSearchBar, SearchBar } from "./SearchBar";
|
||||
import { SearchResultsDisplay } from "./SearchResultsDisplay";
|
||||
import { SourceSelector } from "./filtering/Filters";
|
||||
import { CCPairBasicInfo, DocumentSet, Tag, User } from "@/lib/types";
|
||||
import {
|
||||
Quote,
|
||||
SearchResponse,
|
||||
@@ -374,6 +373,7 @@ export const SearchSection = ({
|
||||
setSearchAnswerExpanded(false);
|
||||
};
|
||||
|
||||
const [previousSearch, setPreviousSearch] = useState<string>("");
|
||||
const [agenticResults, setAgenticResults] = useState<boolean | null>(null);
|
||||
|
||||
let lastSearchCancellationToken = useRef<CancellationToken | null>(null);
|
||||
@@ -398,6 +398,7 @@ export const SearchSection = ({
|
||||
setIsFetching(true);
|
||||
setSearchResponse(initialSearchResponse);
|
||||
setValidQuestionResponse(VALID_QUESTION_RESPONSE_DEFAULT);
|
||||
setPreviousSearch(overrideMessage || query);
|
||||
const searchFnArgs = {
|
||||
query: overrideMessage || query,
|
||||
sources: filterManager.selectedSources,
|
||||
@@ -761,9 +762,12 @@ export const SearchSection = ({
|
||||
/>
|
||||
|
||||
<FullSearchBar
|
||||
setPopup={setPopup}
|
||||
disabled={previousSearch === query}
|
||||
toggleAgentic={
|
||||
disabledAgentic ? undefined : toggleAgentic
|
||||
}
|
||||
previousSearch={previousSearch}
|
||||
showingSidebar={toggledSidebar}
|
||||
agentic={agentic}
|
||||
query={query}
|
||||
|
@@ -222,7 +222,7 @@ export const connectorConfigs: Record<
|
||||
description: "Configure Confluence connector",
|
||||
subtext: `Specify the base URL of your Confluence instance, the space name, and optionally a specific page ID to index. If no page ID is provided, the entire space will be indexed.
|
||||
|
||||
For example, entering "https://pablosfsanchez.atlassian.net/wiki" as the Wiki Base URL, "KB" as the Space, and "164331" as the Page ID will index the specific page at https://pablosfsanchez.atlassian.net/wiki/spaces/KB/pages/164331/Page. If you leave the Page ID empty, it will index the entire KB space.
|
||||
For example, entering "https://your-company.atlassian.net/wiki" as the Wiki Base URL, "KB" as the Space, and "164331" as the Page ID will index the specific page at https:///your-company.atlassian.net/wiki/spaces/KB/pages/164331/Page. If you leave the Page ID empty, it will index the entire KB space.
|
||||
|
||||
Selecting the "Index Recursively" checkbox will index the specified page and all of its children.`,
|
||||
values: [
|
||||
|
Reference in New Issue
Block a user