Giter Site home page Giter Site logo

mpolinowski / reactive_search Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.49 MB

A React.js interface for Elasticsearch 7.8 using reactivesearch 3

Home Page: https://wiki.instar.com/Search/

CSS 6.88% JavaScript 80.38% HTML 12.74%
reactivesearch elasticsearch7 search-interface create-react-app reactjs

reactive_search's Introduction

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits. You will also see any lint errors in the console.

ReactiveSearch Elasticsearch Interface

ReactiveSearch App

We can either add ReactiveSearch to an existing app or create a boilerplate app with Create React App (CRA):

create-react-app search-app && cd search-app

Install ReactiveSearch

We will fetch and install reactivesearch module using yarn or npm.

npm install @appbaseio/reactivesearch

Building your App

Lets add our first ReactiveSearch component: ReactiveBase, it is a backend connector where we can configure the Elasticsearch index / authorization setup.

We will update our src/App.js file to add ReactiveBase component and connect them to our local instance of Elasticsearch 7.8:

import React, { Component } from "react";

import {
  ReactiveBase,
  CategorySearch,
  SelectedFilters,
  ReactiveList,
  SingleList,
  MultiList,
  ResultList,
} from "@appbaseio/reactivesearch";

const { ResultListWrapper } = ReactiveList;

const flexBox = {
  display: "flex",
  marginTop: 20,
};

const flexColumn = {
  flexDirection: "row",
};

const tagsSelector = {
  minHeight: "100%",
};

class App extends Component {
  render() {
    return (
      <ReactiveBase url="http://localhost:9200" app="wiki_ssr_en_2020_07_06">
        <CategorySearch
          componentId="q"
          //title="WikiSearch"
          placeholder="INSTAR Search Assistant"
          categoryField="chapter.raw"
          defaultValue={{
            term: "first steps",
            category: "*",
          }}
          react={{
            and: ["chapter_filter", "tag_filter", "type_filter"],
          }}
          dataField={["title", "tags", "abstract", "description"]}
          fieldWeights={[8, 10, 5, 3]}
          //queryFormat="or"
          searchOperators="true"
          autosuggest={true}
          highlight={true}
          //highlightField="abstract"
          defaultSuggestions={[
            { label: "First Steps", value: "first steps" },
            { label: "Installation", value: "installation" },
            { label: "Web User Interface", value: "web user interface" },
            { label: "InstarVision", value: "instarvision" },
          ]}
          fuzziness={1}
          debounce={100}
          showFilter={true}
          filterLabel="Filter"
          URLParams={true}
        />
        <SelectedFilters />
        <div style={flexBox}>
          <div style={flexColumn}>
            <SingleList
              componentId="chapter_filter"
              dataField="chapter.raw"
              title="Chapters"
              size={100}
              sortBy="count"
              defaultValue="All Chapters"
              selectAllLabel="All Chapters"
              showRadio={true}
              showCount={true}
              showSearch={false}
              //placeholder="Search Chapters"
              react={{
                and: ["q"],
              }}
              showFilter={true}
              filterLabel="Filter"
              URLParams={false}
              loader="Loading ..."
            />

            <hr />

            <SingleList
              componentId="type_filter"
              dataField="type.raw"
              title="Type"
              size={100}
              sortBy="count"
              defaultValue="All Types"
              selectAllLabel="All Types"
              showRadio={true}
              showCount={true}
              showSearch={false}
              react={{
                and: ["q"],
              }}
              showFilter={true}
              filterLabel="Filter"
              URLParams={false}
              loader="Loading ..."
            />

            <hr />

            <MultiList
              componentId="tag_filter"
              dataField="tags.raw"
              title="Tags"
              react={{
                and: ["q"],
              }}
              showSearch={false}
              style={tagsSelector}
              URLParams={false}
              loader="Loading ..."
            />

            <hr />
          </div>{" "}
          {/* FlexColumn */}
          <ReactiveList
            from={0}
            size={15}
            pagination
            react={{
              and: ["q", "chapter_filter", "tag_filter", "type_filter"],
            }}
            componentId="SearchResult"
          >
            {({ data, error, loading }) => (
              <ResultListWrapper>
                {data.map((item) => (
                  <a href={"https://wiki.instar.com" + item.sublink1}>
                    <ResultList key={item._id}>
                      <ResultList.Image
                        src={"https://wiki.instar.com/" + item.imagesquare}
                      />
                      <ResultList.Content>
                        <ResultList.Title
                          dangerouslySetInnerHTML={{
                            __html: item.title,
                          }}
                        />
                        <ResultList.Description
                          dangerouslySetInnerHTML={{
                            __html: item.abstract,
                          }}
                        />
                      </ResultList.Content>
                    </ResultList>
                  </a>
                ))}
              </ResultListWrapper>
            )}
          </ReactiveList>
        </div>{" "}
        {/* FlexBox */}
      </ReactiveBase>
    );
  }
}

export default App;

reactive_search's People

Contributors

mpolinowski avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.