Skip to content

Commit

Permalink
Merge pull request #976 from filecoin-project/@martinalong/elastic-se…
Browse files Browse the repository at this point in the history
…arch-v1

@martinalong/elastic search v1
  • Loading branch information
martinalong committed Nov 1, 2021
2 parents b2135c2 + 745bcd5 commit 2d33c0e
Show file tree
Hide file tree
Showing 37 changed files with 1,495 additions and 353 deletions.
34 changes: 17 additions & 17 deletions common/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ export const sendFilecoin = async (data) => {
// }
// };

export const search = async (data) => {
return await returnJSON(`/api/search/search`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};

export const checkUsername = async (data) => {
return await returnJSON(`/api/users/check-username`, {
...DEFAULT_OPTIONS,
Expand Down Expand Up @@ -196,17 +203,17 @@ export const createSubscription = async (data) => {
});
};

export const search = async (data) => {
await Websockets.checkWebsocket();
if (Strings.isEmpty(data.query)) {
return { decorator: "NO_SERVER_TRIP", data: { results: [] } };
}
// export const search = async (data) => {
// await Websockets.checkWebsocket();
// if (Strings.isEmpty(data.query)) {
// return { decorator: "NO_SERVER_TRIP", data: { results: [] } };
// }

return await returnJSON(`${Environment.URI_LENS}/search`, {
...CORS_OPTIONS,
body: JSON.stringify({ data }),
});
};
// return await returnJSON(`${Environment.URI_LENS}/search`, {
// ...CORS_OPTIONS,
// body: JSON.stringify({ data }),
// });
// };

export const createFile = async (data) => {
await Websockets.checkWebsocket();
Expand Down Expand Up @@ -303,13 +310,6 @@ export const updateStatus = async (data) => {
});
};

export const updateSearch = async (data) => {
return await returnJSON(`/api/search/update`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};

// export const checkCIDStatus = async (data) => {
// return await returnJSON(`/api/data/cid-status`, {
// ...DEFAULT_OPTIONS,
Expand Down
2 changes: 0 additions & 2 deletions common/user-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ export const signOut = async ({ viewer }) => {

// NOTE(jim): Permanently deletes you, forever.
export const deleteMe = async ({ viewer }) => {
await Actions.updateSearch("delete-user");

let response = await Actions.deleteViewer();

if (Events.hasError(response)) {
Expand Down
4 changes: 0 additions & 4 deletions components/core/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,6 @@ export default class ApplicationPage extends React.Component {
});
}

if (newAccount) {
Actions.updateSearch("create-user");
}

// let redirected = this._handleURLRedirect();
// if (!redirected) {
// this._handleAction({ type: "NAVIGATE", value: "NAV_DATA" });
Expand Down
49 changes: 30 additions & 19 deletions components/core/ApplicationHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as Events from "~/common/custom-events";
import * as Styles from "~/common/styles";
import * as Upload from "~/components/core/Upload";
import * as Filter from "~/components/core/Filter";
import * as Actions from "~/common/actions";

import {
ApplicationUserControls,
Expand All @@ -18,17 +19,17 @@ import { ButtonPrimary, ButtonTertiary } from "~/components/system/components/Bu
import { Match, Switch } from "~/components/utility/Switch";
import { Show } from "~/components/utility/Show";
import { useField, useMediaQuery } from "~/common/hooks";
import { Input } from "~/components/system";
import { Input } from "~/components/system/components/Input";
import { AnimatePresence, motion } from "framer-motion";

const STYLES_SEARCH_COMPONENT = (theme) => css`
background-color: transparent;
border-radius: 8px;
box-shadow: none;
height: 100%;
input {
height: 100%;
padding: 0px;
padding: 0px 4px;
border-radius: 0px;
}
&::placeholder {
color: ${theme.semantic.textGray};
Expand Down Expand Up @@ -134,6 +135,7 @@ export default function ApplicationHeader({ viewer, page, data, onAction }) {
showDropdown: false,
popup: null,
isRefreshing: false,
query: "",
});

const _handleTogglePopup = (value) => {
Expand All @@ -144,23 +146,30 @@ export default function ApplicationHeader({ viewer, page, data, onAction }) {
}
};

const handleCreateSearch = (searchQuery) => {
setState((prev) => ({ ...prev, showDropdown: false }));
Events.dispatchCustomEvent({
name: "show-search",
detail: {
initialValue: searchQuery,
},
const _handleInputChange = (e) => {
setState((prev) => ({ ...prev, query: e.target.value }));
};

//TODO(amine): plug in the right values
//for more context, look at node_common/managers/search/search.js
//types: leaving it null searches everything. Doing ["SLATE"] searches just slates, doing ["USER", "FILE"] searches users and files.
//globalSearch: whether you are just searching the user's files/slates or global files/slates. This option doesn't exist for searching users since there is no notion of public or private users
//tagIds: only applies when searching files. the ids of the tags (aka collections) you are searching within. aka if you only want to search for files in a given slate, provide that slate's id. If no tag ids are provided, it searches all files
//grouped: whether to group the results by type (slate, user, file) when searching multiple types. Doesn't apply when searching only one type e.g. types: ["SLATE"]
const handleSearch = async () => {
const response = await Actions.search({
types: null,
query: state.query,
globalSearch: true,
tagIds: null,
grouped: true,
});
console.log(response);
};

const {
getFieldProps,
value: searchQuery,
setFieldValue,
} = useField({
const { getFieldProps, value: searchQuery, setFieldValue } = useField({
initialValue: "",
onSubmit: handleCreateSearch,
onSubmit: handleSearch,
});

const handleDismissSearch = () => setFieldValue("");
Expand Down Expand Up @@ -198,15 +207,17 @@ export default function ApplicationHeader({ viewer, page, data, onAction }) {
full
placeholder={`Search ${!viewer ? "slate.host" : ""}`}
inputCss={STYLES_SEARCH_COMPONENT}
onSubmit={handleCreateSearch}
onSubmit={handleSearch}
name="search"
{...getFieldProps()}
onChange={_handleInputChange}
value={state.query}
/>
</div>
<Upload.Provider page={page} data={data} viewer={viewer}>
<Upload.Root data={data}>
<div css={STYLES_RIGHT}>
<Actions
<UserActions
uploadAction={
<Upload.Trigger
viewer={viewer}
Expand Down Expand Up @@ -249,7 +260,7 @@ export default function ApplicationHeader({ viewer, page, data, onAction }) {
);
}

const Actions = ({ uploadAction, isSignedOut, isSearching, onAction, onDismissSearch }) => {
const UserActions = ({ uploadAction, isSignedOut, isSearching, onAction, onDismissSearch }) => {
const authActions = React.useMemo(
() => (
<>
Expand Down
5 changes: 5 additions & 0 deletions node_common/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ export const MICROLINK_API_KEY = process.env.MICROLINK_API_KEY;

//NOTE(martina): Estuary
export const ESTUARY_API_KEY = process.env.ESTUARY_API_KEY;

//NOTE(martina): Elastic search
export const ELASTIC_SEARCH_CLOUD_ID = process.env.ELASTIC_SEARCH_CLOUD_ID;
export const ELASTIC_SEARCH_API_KEY_ID = process.env.ELASTIC_SEARCH_API_KEY_ID;
export const ELASTIC_SEARCH_API_KEY = process.env.ELASTIC_SEARCH_API_KEY;
99 changes: 0 additions & 99 deletions node_common/managers/search.js

This file was deleted.

49 changes: 49 additions & 0 deletions node_common/managers/search/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
createUserIndex,
createFileIndex,
createSlateIndex,
deleteUserIndex,
deleteFileIndex,
deleteSlateIndex,
} from "~/node_common/managers/search/manage";
import {
searchMultiple,
searchUser,
searchSlate,
searchFile,
} from "~/node_common/managers/search/search";
import {
indexUser,
indexSlate,
indexFile,
updateUser,
updateSlate,
updateFile,
deleteUser,
deleteSlate,
deleteFile,
} from "~/node_common/managers/search/update";

const SearchManager = {
createUserIndex,
createFileIndex,
createSlateIndex,
deleteUserIndex,
deleteFileIndex,
deleteSlateIndex,
indexUser,
indexSlate,
indexFile,
updateUser,
updateSlate,
updateFile,
deleteUser,
deleteSlate,
deleteFile,
searchMultiple,
searchUser,
searchSlate,
searchFile,
};

export default SearchManager;

0 comments on commit 2d33c0e

Please sign in to comment.