Skip to content

Commit

Permalink
Merge pull request #5534 from bcgov/test-rook-AS-FOIMOD-3638
Browse files Browse the repository at this point in the history
FOIMOD-3638-Full Text Search - Boolean Operators
  • Loading branch information
aparna-aot authored Jan 21, 2025
2 parents f3a934e + 36af03a commit 4913c14
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 135 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ services:
- REACT_APP_SESSION_SECURITY_KEY=${REACT_APP_SESSION_SECURITY_KEY}
- REACT_APP_FOI_SOLR_API_BASE=${FOI_SOLR_API_BASE}
- REACT_APP_SEARCH_KEYWORD_LIMIT=${SEARCH_KEYWORD_LIMIT}
- REACT_APP_SOLR_DOC_SEARCH_LIMIT=${SOLR_DOC_SEARCH_LIMIT}
volumes:
- ".:/app"
- "/app/node_modules"
Expand Down
2 changes: 2 additions & 0 deletions forms-flow-web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ARG REACT_APP_RECORD_DOWNLOAD_SIZE_LIMIT
ARG REACT_APP_SESSION_SECURITY_KEY
ARG REACT_APP_FOI_SOLR_API_BASE
ARG REACT_APP_SEARCH_KEYWORD_LIMIT
ARG REACT_APP_SOLR_DOC_SEARCH_LIMIT


ENV NODE_ENV ${NODE_ENV}
Expand Down Expand Up @@ -78,6 +79,7 @@ ENV REACT_APP_RECORD_DOWNLOAD_SIZE_LIMIT ${REACT_APP_RECORD_DOWNLOAD_SIZE_LIMIT}

ENV REACT_APP_FOI_SOLR_API_BASE ${REACT_APP_FOI_SOLR_API_BASE}
ENV REACT_APP_SEARCH_KEYWORD_LIMIT ${REACT_APP_SEARCH_KEYWORD_LIMIT}
ENV REACT_APP_SOLR_DOC_SEARCH_LIMIT ${REACT_APP_SOLR_DOC_SEARCH_LIMIT}

# add `/app/node_modules/.bin` to $PATH
ENV PATH /forms-flow-web/app/node_modules/.bin:$PATH
Expand Down
2 changes: 2 additions & 0 deletions forms-flow-web/Dockerfile.local
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ARG REACT_APP_RECORD_DOWNLOAD_SIZE_LIMIT
ARG REACT_APP_SESSION_SECURITY_KEY
ARG REACT_APP_FOI_SOLR_API_BASE
ARG REACT_APP_SEARCH_KEYWORD_LIMIT
ARG REACT_APP_SOLR_DOC_SEARCH_LIMIT

ENV NODE_ENV ${NODE_ENV}
ENV GENERATE_SOURCEMAP ${GENERATE_SOURCEMAP}
Expand Down Expand Up @@ -69,6 +70,7 @@ ENV REACT_APP_RECORD_DOWNLOAD_SIZE_LIMIT ${REACT_APP_RECORD_DOWNLOAD_SIZE_LIMIT}
ENV REACT_APP_SESSION_SECURITY_KEY ${REACT_APP_SESSION_SECURITY_KEY}
ENV REACT_APP_FOI_SOLR_API_BASE ${REACT_APP_FOI_SOLR_API_BASE}
ENV REACT_APP_SEARCH_KEYWORD_LIMIT ${REACT_APP_SEARCH_KEYWORD_LIMIT}
ENV REACT_APP_SOLR_DOC_SEARCH_LIMIT ${REACT_APP_SOLR_DOC_SEARCH_LIMIT}
# add `/app/node_modules/.bin` to $PATH
ENV PATH /forms-flow-web/app/node_modules/.bin:$PATH

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { httpGETRequest } from "../../httpRequestHandler";
import { httpGETRequest, httpPOSTRequest} from "../../httpRequestHandler";
import API from "../../endpoints";
import { catchError } from "./foiServicesUtil";
import UserService from "../../../services/UserService";
Expand Down Expand Up @@ -69,10 +69,9 @@ export const getSolrKeywordSearchData = ({
errorCallback,
dispatch,
}) => {
httpGETRequest(
API.FOI_GET_CROSSTEXTSEARCH_REQUEST_DETAILS,
{"requestnumbers": foirequestNumbers},
UserService.getToken())
let requestjson={"requestnumbers":foirequestNumbers}
let apiUrlPost = API.FOI_GET_CROSSTEXTSEARCH_REQUEST_DETAILS;
httpPOSTRequest(apiUrlPost, requestjson, UserService.getToken() ?? '', true)
.then((res) => {
if (res.data) {
callback(res.data);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { createContext, useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { fetchFOIProgramAreaList } from "../../../../../apiManager/services/FOI/foiMasterDataServices";
import { fetchAdvancedSearchData } from "../../../../../apiManager/services/FOI/foiAdvancedSearchServices";
import {getCrossTextSearchAuth, getSolrKeywordSearchData,
getKeywordSearchRequestDetails} from "../../../../../apiManager/services/FOI/foiKeywordSearchServices"
import { errorToast } from "../../../../../helper/FOI/helper";
import { setKeywordSearchParams } from "../../../../../actions/FOI/foiRequestActions";
import { SOLR_DOC_SEARCH_LIMIT } from "../../../../../constants/constants";

export const ActionContext = createContext();
ActionContext.displayName = "KeywordSearchContext";
Expand All @@ -14,9 +14,7 @@ export const ActionProvider = ({ children }) => {

const [queryData, setQueryData] = useState(null);
const [keywordSearchLoading, setKeywordSearchLoading] = useState(false);
const [keywordSearchComponentLoading, setKeywordSearchComponentLoading] =
useState(true);

const [keywordSearchComponentLoading, setKeywordSearchComponentLoading] = useState(false);
const [searchResults, setSearchResults] = useState(null);
const keywordSearchParams = useSelector((state) => state.foiRequests.foiKeywordSearchParams);

Expand All @@ -39,11 +37,35 @@ export const ActionProvider = ({ children }) => {

const generateSolrQueryParams = (queryData) => {
let queryParts = [];
let booleanKeywords=[];
if (queryData.keywords.length > 0) {
const keywords = queryData.keywords
.map(keyword => `${keyword}`) // Properly quote keywords
.join(",");
queryParts.push(keywords);
let andKeywords= queryData.keywords?.filter(
(keyword) =>(keyword.category === "AND"));
let orKeywords= queryData.keywords?.filter(
(keyword) =>(keyword.category === "OR"));
let notKeywords= queryData.keywords?.filter(
(keyword) =>(keyword.category === "NOT"));

if (andKeywords.length > 0) {
let andPart = andKeywords.map((keyword) => keyword.text).join(" AND ");
booleanKeywords.push(andPart);
}
if (orKeywords.length > 0) {
let orPart = orKeywords.map((keyword) => keyword.text).join(" OR ");
booleanKeywords.push(orPart);
}
if (notKeywords.length > 0) {
let notPart = notKeywords.map((keyword) => `NOT ${keyword.text}`).join(" NOT ");
// if (booleanKeywords.length > 0) {
// notPart += ` NOT ${booleanKeywords}`;
// }
booleanKeywords.push(notPart);
}
if (booleanKeywords.length > 0) {
queryParts.push(booleanKeywords.join(" "));
}
//queryParts.push(keywords);
console.log("\nqueryParts::",queryParts);
}
// Handle received date range
if (queryData.fromDate || queryData.toDate) {
Expand All @@ -57,13 +79,12 @@ const generateSolrQueryParams = (queryData) => {
}
const query = queryParts.join(" AND ");
console.log("\nquery:",query)
return { df: "foidocumentsentence", q: query };
return { df: "foidocumentsentence", q: query, rows:SOLR_DOC_SEARCH_LIMIT };
};

const convertToISO = (dateStr) => {
if(!!dateStr){
const date = new Date(`${dateStr}T00:00:00Z`);
// Convert to ISO 8601 format
return date.toISOString();
}
else
Expand Down Expand Up @@ -106,6 +127,7 @@ const convertToISO = (dateStr) => {
}
else{
setKeywordSearchComponentLoading(false);
setSearchResults([]);
}
},
errorCallback: (message) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,6 @@ const DataGridKeywordSearch = ({ userDetail }) => {
}
};

// const renderDocReviewerForRequest = (e, row) => {
// e.preventDefault()
// if (row.ministryrequestid) {
// dispatch(
// push(
// `${DOC_REVIEWER_WEB_URL}/foi/${row.ministryrequestid}`
// )
// );
// }
// };

const hyperlinkTooltipRenderCell = (params) => {
let link;
if (params.row.ministryrequestid) {
Expand Down Expand Up @@ -107,24 +96,17 @@ const DataGridKeywordSearch = ({ userDetail }) => {

const goToRecordsRenderCell = (params) => {
const keywordSearchParam = keywordSearchParamsRef.current;
console.log("goToRecordsRenderCell-",keywordSearchParam);
let keywordList = [];

let link;
if (params.row.ministryrequestid) {
if (keywordSearchParam?.keywords?.length > 0) {
const keywords = keywordSearchParam?.keywords
.map(keyword => `${keyword}`) // Properly quote keywords
.join(",");
keywordList.push(keywords);
}
console.log("keywordList:", keywordList);
let queryString= {"query": keywordList };
if (params.row.ministryrequestid && keywordSearchParam?.keywords?.length > 0) {
const keywords = keywordSearchParam.keywords
.filter(keyword => keyword.category.toUpperCase() !== "NOT")
.map(keyword => keyword.text)
.join(",");
//console.log("keywordList:", keywordList);
let queryString= {"query": keywords };
const queryStringParam = new URLSearchParams(queryString).toString();
const formattedQueryString = queryStringParam.replace(/\+/g, '%20');
console.log("formattedQueryString:", formattedQueryString);
link = `${DOC_REVIEWER_WEB_URL}/foi/${params.row.ministryrequestid}?${formattedQueryString}`;
console.log("link:", link);
}
return (
<Link
Expand Down Expand Up @@ -221,19 +203,12 @@ const DataGridKeywordSearch = ({ userDetail }) => {

const classes = useStyles();

const defaultRowsState = { page: 0, pageSize: 100 };
const [rowsState, setRowsState] = useState(
Object.keys(keywordSearchParams).length > 0 ?
{page: keywordSearchParams.page - 1, pageSize: keywordSearchParams.size} :
defaultRowsState
);

const defaultRowsState = { page: 0, pageSize: 10 };
const [rowsState, setRowsState] = useState(defaultRowsState);
const defaultSortModel = [
{ field: "requeststatus", sort: "desc" },
// { field: "receivedDateUF", sort: "desc" },
];

const [sortModel, setSortModel] = useState(keywordSearchParams?.sort || defaultSortModel);
const [sortModel, setSortModel] = useState(defaultSortModel);

useEffect(() => {
if (searchResults) {
Expand All @@ -253,6 +228,33 @@ const DataGridKeywordSearch = ({ userDetail }) => {

const columnsRef = React.useRef(tableInfo?.columns || []);

// Function to get paginated data
const getPaginatedRows = (sortedRows) => {
const startIndex = rowsState.page * rowsState.pageSize;
const endIndex = startIndex + rowsState.pageSize;
return sortedRows.slice(startIndex, endIndex); // Correctly slice rows for pagination
};
// Function to sort data locally
const getSortedRows = () => {
if (!Array.isArray(searchResults) || searchResults.length === 0) return [];
if (sortModel.length === 0) return searchResults;
const { field, sort } = sortModel[0];
return [...searchResults].sort((a, b) => {
if (a[field] < b[field]) return sort === "asc" ? -1 : 1;
if (a[field] > b[field]) return sort === "asc" ? 1 : -1;
return 0;
});
};

// Compute rows to display (sorted and paginated)
const rows = React.useMemo(() => {
const sortedRows = getSortedRows();
let currentPageRows= getPaginatedRows(sortedRows); // Get rows for the current page
console.log("currentPageRows:",currentPageRows)
return currentPageRows
}, [searchResults, rowsState, sortModel]);


if (keywordSearchComponentLoading && queryData) {
return (
<Grid item xs={12} container alignItems="center">
Expand All @@ -279,7 +281,8 @@ const DataGridKeywordSearch = ({ userDetail }) => {
autoHeight
className="foi-data-grid"
getRowId={(row) => row.requestnumber}
rows={searchResults || []}
//rows={searchResults || []}
rows={rows} // Display only the current page's rows
columns={columnsRef?.current}
rowHeight={30}
headerHeight={50}
Expand All @@ -289,20 +292,19 @@ const DataGridKeywordSearch = ({ userDetail }) => {
hideFooterSelectedRowCount={true}
disableColumnMenu={true}
pagination
paginationMode="server"
initialState={{
pagination: rowsState
}}
paginationMode="server"
onPageChange={(newPage) => setRowsState((prev) => ({ ...prev, page: newPage }))}
onPageSizeChange={(newpageSize) =>
setRowsState((prev) => ({ ...prev, pageSize: newpageSize }))
}
components={{
Footer: ()=> <CustomFooter rowCount={searchResults?.length || 0} defaultSortModel={tableInfo.sort} footerFor={"advancedsearch"}></CustomFooter>
Footer: ()=> <CustomFooter rowCount={searchResults?.length || 0} defaultSortModel={defaultSortModel} footerFor={"advancedsearch"}></CustomFooter>
}}
sortingOrder={["desc", "asc"]}
sortModel={[sortModel[0]]}
sortingMode={"server"}
onSortModelChange={(model) => {
if (model.length > 0) {
setSortModel(model)
Expand Down
Loading

0 comments on commit 4913c14

Please sign in to comment.