@windingtree/wt-search-api

0.8.0 • Public • Published

WT Search API

Greenkeeper badge

API written in nodejs to fetch information from the Winding Tree platform.

Work in progress. Discussion on https://groups.google.com/forum/#!topic/windingtree/J_6aRddPVWY

Requirements

  • Nodejs >=10

Development

In order to install and run tests, we must:

git clone git@github.com:windingtree/wt-search-api.git
nvm install
npm install
npm test

Running dev mode

With all the dependencies installed, you can start the dev server.

First step is to initialize the SQLite database used to store your data. If you want to use a different database, feel free to change the connection settings in the appropriate configuration file in src/config/.

npm run createdb-dev

If you'd like to start afresh later, just delete the .dev.sqlite file.

Now we can run our dev server.

npm run dev

By default, this will try to connect to an instance of wt-read-api running locally on http://localhost:3000 and index the hotels from there. You can override the default in an appropriate config file in src/config or with READ_API_URL environment variable.

Right after you start your node, it will try to sync and index all of the data immediately.

Running this server

Docker

You can run the whole API in a docker container, and you can control which config will be used by passing an appropriate value to WT_CONFIG variable at runtime. Database will be setup during the container startup in the current setup. You can skip this with SKIP_DB_SETUP environment variable.

$ docker build -t windingtree/wt-search-api .
$ docker run -p 8080:1918 -e WT_CONFIG=playground windingtree/wt-search-api

After that you can access the wt-search-api on local port 8080.

NPM

You can install and run this from NPM as well:

$ npm install -g @windingtree/wt-search-api
$ WT_CONFIG=playground wt-search-api

This will also create a local SQLite instance in the directory where you run the wt-search-api command. To prevent that, you can suppress DB creation with SKIP_DB_SETUP environment variable.

Running in production

You can customize the behaviour of the instance by many environment variables which get applied if you run the API with WT_CONFIG=envvar. These are:

  • WT_CONFIG - Which config will be used. Defaults to dev.
  • PORT - HTTP Port where the API will listen, defaults to 1918.
  • BASE_URL - Base URL of this API instance, for example https://playground-search-api.windingtree.com
  • READ_API_URL - Read API url, for example https://playground-api.windingtree.com
  • DB_CLIENT - Knex database client name, for example sqlite3.
  • DB_CLIENT_OPTIONS - Knex database client options as JSON string, for example {"filename": "./envvar.sqlite"}.
  • LOG_LEVEL - Log level, defaults to info.
  • SKIP_DB_SETUP - Whether to not setup new database upon startup.
  • DEFAULT_PAGE_SIZE - How many items will be returned by default. Defaults to 30.
  • MAX_PAGE_SIZE - What's the maximum value of limit query parameter. Defaults to 300.
  • SYNC_INTERVAL - How often will a complete resync occur in seconds. Defaults to one hour.
  • SYNC_INITIAL - Perform the initial sync immediately after server start? Defaults to true.

We recommend to use a more robust database than sqlite3 for any serious deployment.

Examples

Search and sort by location

The following command will get you the 3 closest hotels to 46.770066, 23.600819 sorted by distance from this point and no further than 30 kilometers.

curl -X GET "https://playground-search-api.windingtree.com/hotels?location=46.770066,23.600819:30&sortByDistance=46.770066,23.600819&limit=3" -H "accept: application/json"

You are not required to use both filters and sorts simultaneously, you can pick one or the other or combine them.

How to add a new index?

This has multiple steps:

  1. Prepare a db model in src/db/indexed/models and register it in src/db/indexed/index.js.
  2. Prepare a query parser in src/services/query-parser/indices and register it in src/services/query-parser/index.js.
  3. Prepare an indexer in src/services/indexer/indices and register it in src/services/indexers/index.js.
  4. Add a few tests for all components.
  5. You're good to go!

Proposed architecture

Proposed architecture

Ideal flow

  • Hotel writes its data to the platform with Write API.
  • Write API sends notifications about hotel data changes via Update API.
  • If a new hotel pops up, Subscriptions Management makes sure that the Search API is tracking all the hotel data changes.
  • Subscription handler (or Resync cron job) tells the Crawler to collect the changed data via Read API (currently, the version 0.8.x is assumed).
  • Crawler puts a copy of the data to Permanent storage.
  • Crawler also bumps the Indexer and Price Computation components to start work with the changed data.
  • Indexer re-indexes the hotel data from Permanent Storage to make search easier where possible (such as location data, description for fulltext etc.) and puts them to Indexed Storage.
  • Price computation (silly name) re-computes all of the prices based on new hotel information from Permanent Storage and puts them to Price Storage. It's not really clear how it should know which prices it should compute though.
  • OTAs (or other users of the system) are posting queries via Query API and they are getting quick responses

Various notes

  • Prices (and all other guest-related) query results might be hard to pre-compute. It might be feasible to collect common query types and pre-compute appropriate data for that.
  • There's yet no decision on how the Query API will communicate with the outside world. Contenders probably are: REST API with query strings, REST API with custom query language, GraphQL endpoint
  • Query API has to offer ways of sorting the data and some relevance score for search results. Also we cannot forget about pagination.
  • Resync CRON job has to be in place because there's no guarantee that the outside system is reliable and that every hotel uses Update API.
  • Indexed and Price storages are fast, ideally in-memory databases.
  • Permanent storage is in place if Indexed Storage and/or Price Storage get somehow corrupted or destroyed. The Search box can re-index the whole WT platform way faster than if it had to get all data from various distributed storages.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.9.0-23e3c134bea83cfa468cb098e55235d42770a5bb.00develop
0.8.00latest

Version History

VersionDownloads (Last 7 Days)Published
0.8.00
0.9.0-23e3c134bea83cfa468cb098e55235d42770a5bb.00
0.8.0-96b0cb844bb4a80aa71aec84fcbdd14344c5f00c.00
0.8.0-81d72c889f5f7a68d8f15dd1e202f1a5ae5b4c4c.00
0.8.0-021de14eb53e91cfeff991606334a5c3a373f75d.00
0.7.10
0.8.0-ed6ee676686dea4abf13816e6af4bf4d90c87663.00
0.8.0-50878a8249255d0038894f0ae9f5eadc4d4ecce7.00
0.7.00
0.8.0-583edec8d151b149420ac6b0ce3ddb594b3768b7.00
0.7.0-5032d1acd9d07d78c2a9a5a586a7b617c609af60.00
0.7.0-e98f72bb9212fd6f942917205879d0de96c0d6fe.00
0.7.0-0adc86b5d80da3e62bfd9ca93d36ed6f36ff2fec.00
0.7.0-ec2e8efd7736ef816bd4d4cb52c24ba9f47fcae0.00
0.7.0-dfa13ee65f2e9c75cc4d491abc252f2ab05a8a6a.01
0.7.0-fb5ef6f3bd76e1d99380e9eff9ca4e6ed8a5e1bf.00
0.7.0-8683011cfcd1ad2d782910c8d91a74dbf933b985.00
0.7.0-623aa5d9e92a1fff322e9f508f4b84f31d408aa1.00
0.7.0-71382a513bfe246f17f6e39b70be82223114ac46.00
0.7.0-c8897bfebfeb1423e8ef6359027a0f07fd7bec07.01
0.6.11
0.7.0-5fda4e16c62e2a8919188ea3732cd5346419ec5b.00
0.7.0-01225b915baa530b8b3c67a25ff5f6b77fbe86ba.00
0.6.0-5390e2b02732221cb8d11dcbaff5eb1d2c42bd1e.00
0.6.0-bbe220150dc0d7f27455cd107257bcfcccd4fdf0.00
0.6.0-b7f013d340c4cfbab02141db729c9a3ead68d019.00
0.6.0-d30676ac4934d390bbf4b3a87c7b04f693f70943.00
0.6.0-3a82bb7435a8ced95cc27bd8e84c3b551c3a013a.00
0.6.0-e54425236978e01323b12944f2d9036b221b77b9.00
0.5.00
0.6.0-3ab30273e7ef1764b93b5602a473bf03d0bf95be.01
0.5.0-28c81f9dbc27694a18b1f788939f6b4618597608.00
0.5.0-98d1a08535a5f306dfca1f58b3a156ade8d51cc5.00
0.5.0-c392312fb4c70d3247fdca7b37e50fa348e54803.00
0.5.0-ed7f48fa9c5fe15dac0320189e3d35ca4ca15899.01
0.5.0-6ff2bfa9630a75d9ad093022ff88adc402a5add2.00
0.5.0-8d79e3ca6418de4caae6a941c2c581a4d13aae56.00
0.4.00

Package Sidebar

Install

npm i @windingtree/wt-search-api

Weekly Downloads

5

Version

0.8.0

License

Apache-2.0

Unpacked Size

144 kB

Total Files

54

Last publish

Collaborators

  • kostysh
  • kvakes
  • tomashq