App.js 2.6 KB
import React from "react";
import AppSearchAPIConnector from "@elastic/search-ui-app-search-connector";
import { SearchProvider, Results, SearchBox } from "@elastic/react-search-ui";
import { Layout} from "@elastic/react-search-ui-views";
import "@elastic/react-search-ui-views/lib/styles/styles.css";
import './App.css';

const connector = new AppSearchAPIConnector({
  searchKey: "[search-4td7gan5kcasgygjcyexksrz]",
  engineName: "video-games",
  hostIdentifier: "[private-bhi6v1txusox87eag2c8qgu3]"
});

const configurationOptions = {
    apiConnector: connector,
    searchQuery: {
        search_fields: {
            name: {}
        },
        result_fields: {
            name: {
                snippet: {
                    size: 75
                }
            },
            genre: {
                snippet: {
                    size: 50,
                    fallback: true
                }
            },
            publisher: {
                snippet: {
                    size: 50,
                    fallback: true
                }
            },
            critic_score: {
                raw: {}
            },
            user_score: {
                raw: {}
            },
            platform: {
                snippet: {
                    size: 50,
                    fallback: true
                }
            },
            image_url: {
                raw: {}
            }
        },
        facets: {
            user_score: {
                type: "range",
                ranges: [
                    { from: 0, to: 5, name: "Not good" },
                    { from: 5, to: 7, name: "Not bad" },
                    { from: 7, to: 9, name: "Pretty good" },
                    { from: 9, to: 10, name: "Must play!" }
                ]
            },
            critic_score: {
                type: "range",
                ranges: [
                    { from: 0, to: 50, name: "Not good" },
                    { from: 50, to: 70, name: "Not bad" },
                    { from: 70, to: 90, name: "Pretty good" },
                    { from: 90, to: 100, name: "Must play!" }
                ]
            },
            genre: { type: "value", size: 100 },
            publisher: { type: "value", size: 100},
            platform: { type: "value", size: 100}
        }
    }
};

function App() {
  return (
      <SearchProvider config={configurationOptions}>
        <div className="App">
            <Layout
                header={<SearchBox />}
                bodyContent={<Results titleField="name" urlField="image_url"/>}
            />
        </div>
      </SearchProvider>
  );
}

export default App;