mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-29 05:15:12 +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";
|
import { MagnifyingGlass } from "@phosphor-icons/react";
|
||||||
interface FullSearchBarProps {
|
interface FullSearchBarProps {
|
||||||
|
disabled: boolean;
|
||||||
query: string;
|
query: string;
|
||||||
|
setPopup: (popupSpec: PopupSpec | null) => void;
|
||||||
setQuery: (query: string) => void;
|
setQuery: (query: string) => void;
|
||||||
onSearch: (fast?: boolean) => void;
|
onSearch: (fast?: boolean) => void;
|
||||||
agentic?: boolean;
|
agentic?: boolean;
|
||||||
@@ -14,6 +16,7 @@ interface FullSearchBarProps {
|
|||||||
finalAvailableSources: string[];
|
finalAvailableSources: string[];
|
||||||
tags: Tag[];
|
tags: Tag[];
|
||||||
showingSidebar: boolean;
|
showingSidebar: boolean;
|
||||||
|
previousSearch: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
import { useState, useEffect, useRef } from "react";
|
import { useState, useEffect, useRef } from "react";
|
||||||
@@ -25,6 +28,7 @@ import { SettingsContext } from "../settings/SettingsProvider";
|
|||||||
import { HorizontalSourceSelector, SourceSelector } from "./filtering/Filters";
|
import { HorizontalSourceSelector, SourceSelector } from "./filtering/Filters";
|
||||||
import { CCPairBasicInfo, DocumentSet, Tag } from "@/lib/types";
|
import { CCPairBasicInfo, DocumentSet, Tag } from "@/lib/types";
|
||||||
import { SourceMetadata } from "@/lib/search/interfaces";
|
import { SourceMetadata } from "@/lib/search/interfaces";
|
||||||
|
import { PopupSpec } from "../admin/connectors/Popup";
|
||||||
|
|
||||||
export const AnimatedToggle = ({
|
export const AnimatedToggle = ({
|
||||||
isOn,
|
isOn,
|
||||||
@@ -123,6 +127,7 @@ export const AnimatedToggle = ({
|
|||||||
export default AnimatedToggle;
|
export default AnimatedToggle;
|
||||||
|
|
||||||
export const FullSearchBar = ({
|
export const FullSearchBar = ({
|
||||||
|
disabled,
|
||||||
showingSidebar,
|
showingSidebar,
|
||||||
query,
|
query,
|
||||||
setQuery,
|
setQuery,
|
||||||
@@ -133,8 +138,10 @@ export const FullSearchBar = ({
|
|||||||
documentSets,
|
documentSets,
|
||||||
filterManager,
|
filterManager,
|
||||||
finalAvailableDocumentSets,
|
finalAvailableDocumentSets,
|
||||||
|
setPopup,
|
||||||
finalAvailableSources,
|
finalAvailableSources,
|
||||||
tags,
|
tags,
|
||||||
|
previousSearch,
|
||||||
}: FullSearchBarProps) => {
|
}: FullSearchBarProps) => {
|
||||||
const handleChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
|
const handleChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
|
||||||
const target = event.target;
|
const target = event.target;
|
||||||
@@ -152,8 +159,10 @@ export const FullSearchBar = ({
|
|||||||
!event.shiftKey &&
|
!event.shiftKey &&
|
||||||
!(event.nativeEvent as any).isComposing
|
!(event.nativeEvent as any).isComposing
|
||||||
) {
|
) {
|
||||||
onSearch(agentic);
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
if (!disabled) {
|
||||||
|
onSearch(agentic);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -200,13 +209,12 @@ export const FullSearchBar = ({
|
|||||||
style={{ scrollbarWidth: "thin" }}
|
style={{ scrollbarWidth: "thin" }}
|
||||||
role="textarea"
|
role="textarea"
|
||||||
aria-multiline
|
aria-multiline
|
||||||
placeholder="Search for something..."
|
placeholder="Search for anything..."
|
||||||
value={query}
|
value={query}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
onKeyDown={(event) => {}}
|
onKeyDown={(event) => {}}
|
||||||
suppressContentEditableWarning={true}
|
suppressContentEditableWarning={true}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div
|
<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`}
|
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 && (
|
{toggleAgentic && (
|
||||||
<AnimatedToggle isOn={agentic!} handleToggle={toggleAgentic} />
|
<AnimatedToggle isOn={agentic!} handleToggle={toggleAgentic} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="my-auto pl-2">
|
<div className="my-auto pl-2">
|
||||||
<button
|
<button
|
||||||
|
disabled={disabled}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onSearch(agentic);
|
onSearch(agentic);
|
||||||
}}
|
}}
|
||||||
@@ -236,7 +244,7 @@ export const FullSearchBar = ({
|
|||||||
>
|
>
|
||||||
<SendIcon
|
<SendIcon
|
||||||
size={28}
|
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]"
|
query ? "bg-background-800" : "bg-[#D7D7D7]"
|
||||||
}`}
|
}`}
|
||||||
/>
|
/>
|
||||||
|
@@ -169,7 +169,10 @@ export const SearchResultsDisplay = ({
|
|||||||
<p>Results</p>
|
<p>Results</p>
|
||||||
{!DISABLE_LLM_DOC_RELEVANCE &&
|
{!DISABLE_LLM_DOC_RELEVANCE &&
|
||||||
(contentEnriched || searchResponse.additional_relevance) && (
|
(contentEnriched || searchResponse.additional_relevance) && (
|
||||||
<Tooltip delayDuration={1000} content={`${commandSymbol}O`}>
|
<Tooltip
|
||||||
|
delayDuration={1000}
|
||||||
|
content={<div className="flex">{commandSymbol}O</div>}
|
||||||
|
>
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
performSweep();
|
performSweep();
|
||||||
|
@@ -1,10 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useContext, useEffect, useRef, useState } from "react";
|
import { useContext, useEffect, useRef, useState } from "react";
|
||||||
import { FullSearchBar } from "./SearchBar";
|
import { FullSearchBar, SearchBar } from "./SearchBar";
|
||||||
import { SearchResultsDisplay } from "./SearchResultsDisplay";
|
import { SearchResultsDisplay } from "./SearchResultsDisplay";
|
||||||
import { SourceSelector } from "./filtering/Filters";
|
import { SourceSelector } from "./filtering/Filters";
|
||||||
import { CCPairBasicInfo, DocumentSet, Tag, User } from "@/lib/types";
|
|
||||||
import {
|
import {
|
||||||
Quote,
|
Quote,
|
||||||
SearchResponse,
|
SearchResponse,
|
||||||
@@ -374,6 +373,7 @@ export const SearchSection = ({
|
|||||||
setSearchAnswerExpanded(false);
|
setSearchAnswerExpanded(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [previousSearch, setPreviousSearch] = useState<string>("");
|
||||||
const [agenticResults, setAgenticResults] = useState<boolean | null>(null);
|
const [agenticResults, setAgenticResults] = useState<boolean | null>(null);
|
||||||
|
|
||||||
let lastSearchCancellationToken = useRef<CancellationToken | null>(null);
|
let lastSearchCancellationToken = useRef<CancellationToken | null>(null);
|
||||||
@@ -398,6 +398,7 @@ export const SearchSection = ({
|
|||||||
setIsFetching(true);
|
setIsFetching(true);
|
||||||
setSearchResponse(initialSearchResponse);
|
setSearchResponse(initialSearchResponse);
|
||||||
setValidQuestionResponse(VALID_QUESTION_RESPONSE_DEFAULT);
|
setValidQuestionResponse(VALID_QUESTION_RESPONSE_DEFAULT);
|
||||||
|
setPreviousSearch(overrideMessage || query);
|
||||||
const searchFnArgs = {
|
const searchFnArgs = {
|
||||||
query: overrideMessage || query,
|
query: overrideMessage || query,
|
||||||
sources: filterManager.selectedSources,
|
sources: filterManager.selectedSources,
|
||||||
@@ -761,9 +762,12 @@ export const SearchSection = ({
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<FullSearchBar
|
<FullSearchBar
|
||||||
|
setPopup={setPopup}
|
||||||
|
disabled={previousSearch === query}
|
||||||
toggleAgentic={
|
toggleAgentic={
|
||||||
disabledAgentic ? undefined : toggleAgentic
|
disabledAgentic ? undefined : toggleAgentic
|
||||||
}
|
}
|
||||||
|
previousSearch={previousSearch}
|
||||||
showingSidebar={toggledSidebar}
|
showingSidebar={toggledSidebar}
|
||||||
agentic={agentic}
|
agentic={agentic}
|
||||||
query={query}
|
query={query}
|
||||||
|
@@ -222,7 +222,7 @@ export const connectorConfigs: Record<
|
|||||||
description: "Configure Confluence connector",
|
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.
|
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.`,
|
Selecting the "Index Recursively" checkbox will index the specified page and all of its children.`,
|
||||||
values: [
|
values: [
|
||||||
|
Reference in New Issue
Block a user