+
mutate(INDEXING_STATUS_URL),
};
};
+
+export const useTimeRange = (initialValue?: DateRangePickerValue) => {
+ return useState(null);
+};
diff --git a/web/src/lib/search/interfaces.ts b/web/src/lib/search/interfaces.ts
index 8a4cd78b314b..3e3c6875fd6d 100644
--- a/web/src/lib/search/interfaces.ts
+++ b/web/src/lib/search/interfaces.ts
@@ -1,3 +1,4 @@
+import { DateRangePickerValue } from "@tremor/react";
import { ValidSources } from "../types";
export const FlowType = {
@@ -35,6 +36,7 @@ export interface DanswerDocument {
hidden: boolean;
score: number;
match_highlights: string[];
+ updated_at: string | null;
}
export interface SearchResponse {
@@ -61,6 +63,7 @@ export interface SearchRequestArgs {
query: string;
sources: Source[];
documentSets: string[];
+ timeRange: DateRangePickerValue | null;
updateCurrentAnswer: (val: string) => void;
updateQuotes: (quotes: Quote[]) => void;
updateDocs: (documents: DanswerDocument[]) => void;
diff --git a/web/src/lib/search/qa.ts b/web/src/lib/search/qa.ts
index d594bccbdfe1..ff2bf50ef070 100644
--- a/web/src/lib/search/qa.ts
+++ b/web/src/lib/search/qa.ts
@@ -11,6 +11,7 @@ export const searchRequest = async ({
query,
sources,
documentSets,
+ timeRange,
updateCurrentAnswer,
updateQuotes,
updateDocs,
@@ -29,7 +30,7 @@ export const searchRequest = async ({
let quotes: Quote[] | null = null;
let relevantDocuments: DanswerDocument[] | null = null;
try {
- const filters = buildFilters(sources, documentSets);
+ const filters = buildFilters(sources, documentSets, timeRange);
const response = await fetch("/api/direct-qa", {
method: "POST",
body: JSON.stringify({
diff --git a/web/src/lib/search/streamingQa.ts b/web/src/lib/search/streamingQa.ts
index 92815db1e2df..da83ecd74e8e 100644
--- a/web/src/lib/search/streamingQa.ts
+++ b/web/src/lib/search/streamingQa.ts
@@ -56,6 +56,7 @@ export const searchRequestStreamed = async ({
query,
sources,
documentSets,
+ timeRange,
updateCurrentAnswer,
updateQuotes,
updateDocs,
@@ -75,7 +76,7 @@ export const searchRequestStreamed = async ({
let quotes: Quote[] | null = null;
let relevantDocuments: DanswerDocument[] | null = null;
try {
- const filters = buildFilters(sources, documentSets);
+ const filters = buildFilters(sources, documentSets, timeRange);
const response = await fetch("/api/stream-direct-qa", {
method: "POST",
body: JSON.stringify({
diff --git a/web/src/lib/search/utils.ts b/web/src/lib/search/utils.ts
index a179025a576d..f1be0fcb6270 100644
--- a/web/src/lib/search/utils.ts
+++ b/web/src/lib/search/utils.ts
@@ -1,12 +1,16 @@
import { Source } from "./interfaces";
+import { DateRangePickerValue } from "@tremor/react";
-export const buildFilters = (sources: Source[], documentSets: string[]) => {
+export const buildFilters = (
+ sources: Source[],
+ documentSets: string[],
+ timeRange: DateRangePickerValue | null
+) => {
const filters = {
source_type:
sources.length > 0 ? sources.map((source) => source.internalName) : null,
document_set: documentSets.length > 0 ? documentSets : null,
- // TODO make this a date selector
- time_cutoff: null,
+ time_cutoff: timeRange?.from ? timeRange.from : null,
};
return filters;
diff --git a/web/src/lib/time.ts b/web/src/lib/time.ts
index 26e5204fa8ab..8c53d1b609e8 100644
--- a/web/src/lib/time.ts
+++ b/web/src/lib/time.ts
@@ -1,3 +1,10 @@
+const conditionallyAddPlural = (noun: string, cnt: number) => {
+ if (cnt > 1) {
+ return `${noun}s`;
+ }
+ return noun;
+};
+
export const timeAgo = (
dateString: string | undefined | null
): string | null => {
@@ -10,29 +17,40 @@ export const timeAgo = (
const secondsDiff = Math.floor((now.getTime() - date.getTime()) / 1000);
if (secondsDiff < 60) {
- return `${secondsDiff} second(s) ago`;
+ return `${secondsDiff} ${conditionallyAddPlural(
+ "second",
+ secondsDiff
+ )} ago`;
}
const minutesDiff = Math.floor(secondsDiff / 60);
if (minutesDiff < 60) {
- return `${minutesDiff} minute(s) ago`;
+ return `${minutesDiff} ${conditionallyAddPlural(
+ "minute",
+ secondsDiff
+ )} ago`;
}
const hoursDiff = Math.floor(minutesDiff / 60);
if (hoursDiff < 24) {
- return `${hoursDiff} hour(s) ago`;
+ return `${hoursDiff} ${conditionallyAddPlural("hour", hoursDiff)} ago`;
}
const daysDiff = Math.floor(hoursDiff / 24);
if (daysDiff < 30) {
- return `${daysDiff} day(s) ago`;
+ return `${daysDiff} ${conditionallyAddPlural("day", daysDiff)} ago`;
+ }
+
+ const weeksDiff = Math.floor(daysDiff / 7);
+ if (weeksDiff < 4) {
+ return `${weeksDiff} ${conditionallyAddPlural("week", weeksDiff)} ago`;
}
const monthsDiff = Math.floor(daysDiff / 30);
if (monthsDiff < 12) {
- return `${monthsDiff} month(s) ago`;
+ return `${monthsDiff} ${conditionallyAddPlural("month", monthsDiff)} ago`;
}
const yearsDiff = Math.floor(monthsDiff / 12);
- return `${yearsDiff} year(s) ago`;
+ return `${yearsDiff} ${conditionallyAddPlural("year", yearsDiff)} ago`;
};