Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Engines Connector #919

Merged
merged 4 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@
},
"console": "integratedTerminal",
"sourceMaps": true
},
{
"name": "Jest engines-connector",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
"stopOnEntry": false,
"args": ["--runInBand", "--forceExit", "--detectOpenHandles", "--watch"],
"cwd": "${workspaceRoot}/packages/search-ui-engines-connector",
"preLaunchTask": null,
"runtimeExecutable": null,
"env": {
"NODE_ENV": "test"
},
"console": "integratedTerminal",
"sourceMaps": true
}
]
}
1 change: 1 addition & 0 deletions examples/sandbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@elastic/search-ui-elasticsearch-connector": "1.18.3",
"@elastic/search-ui-site-search-connector": "1.18.3",
"@elastic/search-ui-workplace-search-connector": "1.18.3",
"@elastic/search-ui-engines-connector": "1.18.3",
"@emotion/react": "^11.8.1",
"autoprefixer": "^10.4.7",
"moment": "^2.24.0",
Expand Down
2 changes: 2 additions & 0 deletions examples/sandbox/src/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from "react";
import { Switch } from "react-router-dom";
import Root from "./pages/root";
import Elasticsearch from "./pages/elasticsearch";
import Engines from "./pages/engines";
import AppSearch from "./pages/app-search";
import SiteSearch from "./pages/site-search";
import WorkplaceSearch from "./pages/workplace-search";
Expand All @@ -26,6 +27,7 @@ export default function Router() {
<ApmRoute exact path="/app-search" component={AppSearch} />
<ApmRoute exact path="/site-search" component={SiteSearch} />
<ApmRoute exact path="/workplace-search" component={WorkplaceSearch} />
<ApmRoute exact path="/engines" component={Engines} />

{/* Examples */}
<ApmRoute
Expand Down
163 changes: 163 additions & 0 deletions examples/sandbox/src/pages/engines/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import React from "react";
import "@elastic/eui/dist/eui_theme_light.css";

import EnginesAPIConnector from "@elastic/search-ui-engines-connector";

import {
ErrorBoundary,
Facet,
SearchProvider,
SearchBox,
Results,
PagingInfo,
ResultsPerPage,
Paging,
Sorting,
WithSearch
} from "@elastic/react-search-ui";
import { Layout } from "@elastic/react-search-ui-views";
import "@elastic/react-search-ui-views/lib/styles/styles.css";

const connector = new EnginesAPIConnector({
host: "http://localhost:3002",
engineName: "puggles",
apiKey: "QTJDMHhJVUJENHg5WEJWcXlrWVQ6dXFlcF9QRWdRWHl2Rm9iSndka1Rndw=="
});

const config = {
debug: true,
alwaysSearchOnInitialLoad: true,
apiConnector: connector,
hasA11yNotifications: true,
autocompleteQuery: {
results: {
search_fields: {
name: {}
},
resultsPerPage: 5,
result_fields: {
name: {
snippet: {
size: 100,
fallback: true
}
}
}
}
},
searchQuery: {
filters: [],
search_fields: {
name: {
weight: 3
}
},
result_fields: {
id: { raw: {} },
name: { raw: {}, snippet: { size: 100, fallback: true } },
color: { raw: {} },
age: { raw: {} }
},
disjunctiveFacets: ["color", "age"],
facets: {
color: { type: "value" },
age: {
type: "range",
ranges: [
{ to: 2, name: "New born" },
{ from: 2, to: 3, name: "Puppy" },
{ from: 3, to: 13, name: "Mid" },
{ from: 14, name: "senior" }
]
}
}
}
};

const SORT_OPTIONS = [
{
name: "Relevance",
value: []
},
{
name: "Youngest",
value: [
{
field: "age",
direction: "asc"
}
]
},
{
name: "Oldest",
value: [
{
field: "age",
direction: "desc"
}
]
}
];

export default function App() {
return (
<SearchProvider config={config}>
<WithSearch
mapContextToProps={({ wasSearched }) => ({
wasSearched
})}
>
{({ wasSearched }) => {
return (
<div className="App">
<ErrorBoundary>
<Layout
header={
<SearchBox
debounceLength={0}
autocompleteResults={{
linkTarget: "_blank",
sectionTitle: "Results",
titleField: "name",
urlField: "name"
}}
/>
}
sideContent={
<div>
{wasSearched && (
<Sorting label={"Sort by"} sortOptions={SORT_OPTIONS} />
)}
<Facet
field="color"
label="Color"
filterType="any"
isFilterable={true}
/>
<Facet
field="age"
label="Age"
filterType="any"
isFilterable={true}
/>
</div>
}
bodyContent={
<Results titleField="name" shouldTrackClickThrough={true} />
}
bodyHeader={
<React.Fragment>
{wasSearched && <PagingInfo />}
{wasSearched && <ResultsPerPage />}
</React.Fragment>
}
bodyFooter={<Paging />}
/>
</ErrorBoundary>
</div>
);
}}
</WithSearch>
</SearchProvider>
);
}
Loading