Skip to content

Commit

Permalink
Prevent spam search (onyx-dot-app#2367)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablonyx authored and rajiv chodisetti committed Oct 2, 2024
1 parent d58c0f0 commit d696fd0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
18 changes: 13 additions & 5 deletions web/src/components/search/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +16,7 @@ interface FullSearchBarProps {
finalAvailableSources: string[];
tags: Tag[];
showingSidebar: boolean;
previousSearch: string;
}

import { useState, useEffect, useRef } from "react";
Expand All @@ -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,
Expand Down Expand Up @@ -123,6 +127,7 @@ export const AnimatedToggle = ({
export default AnimatedToggle;

export const FullSearchBar = ({
disabled,
showingSidebar,
query,
setQuery,
Expand All @@ -133,8 +138,10 @@ export const FullSearchBar = ({
documentSets,
filterManager,
finalAvailableDocumentSets,
setPopup,
finalAvailableSources,
tags,
previousSearch,
}: FullSearchBarProps) => {
const handleChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
const target = event.target;
Expand All @@ -152,8 +159,10 @@ export const FullSearchBar = ({
!event.shiftKey &&
!(event.nativeEvent as any).isComposing
) {
onSearch(agentic);
event.preventDefault();
if (!disabled) {
onSearch(agentic);
}
}
};

Expand Down Expand Up @@ -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`}
>
Expand All @@ -226,17 +234,17 @@ export const FullSearchBar = ({
{toggleAgentic && (
<AnimatedToggle isOn={agentic!} handleToggle={toggleAgentic} />
)}

<div className="my-auto pl-2">
<button
disabled={disabled}
onClick={() => {
onSearch(agentic);
}}
className="flex my-auto cursor-pointer"
>
<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]"
}`}
/>
Expand Down
5 changes: 4 additions & 1 deletion web/src/components/search/SearchResultsDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 6 additions & 2 deletions web/src/components/search/SearchSection.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion web/src/lib/connectors/connectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit d696fd0

Please sign in to comment.