---
title: "Tutorial"
author: "Michael Rustler"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Tutorial}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```



## Algolia Configuration

### Interactive Use

```{r eval = FALSE}
config <- algoliar::create_config(path_index_json = "path_to_your_index.json", 
                                  app_id = "your_algolia_application_id",
                                  api_key = "your_algolia_api_key",
                                  index_name = "your_algolia_index_name")

```

### Continious Integration

Using environment variables is necessary if continious integration services (e.g.
[Travis](https://travis.org), [Appveyor](https://appveyor.com) or 
[GitLab CI](https://about.gitlab.com/product/continuous-integration/)). In this 
case you need to specify: 
- `algolia_app_id`: application id
- `algolia_api_key`: api key with sufficient rights (created in Algolia dashboard)
- `algolia_index_name`: index name (created in Algolia dashboard)

All three are defined / created in the [Algolia dashboard](https://www.algolia.com/doc/guides/getting-started/quick-start/tutorials/getting-started-with-the-dashboard/). 



```{r eval = FALSE}

Sys.setenv(algolia_app_id = "your_algolia_application_id",
           algolia_api_key = "your_algolia_api_key",
           algolia_index_name = "your_algolia_index_name")
```

Finally only one parameter is not not explicitly defined yet. It is the path to 
to `index.json` that should be uploaded to Algolia. We use the [Algolia](https://algolia.com) 
search in tandem with the [Hugo](https://gohugo.io) theme [Academic](https://sourcethemes.com/academic). Thus the default value is
`public/index.json`, which usually is the standard deploy location after generating  
the website with `blogdown::build_site()`. 

In this case there is no need to call the `algolia::create_config()` function 
explicitly to upload the `index.json` to Algolia using the function 
`algoliar::algolia_post_batch()`. 

```{r eval = FALSE}

## Upload new index.json to algolia, no need to call algoliar::create_config() 
algoliar::algolia_post_batch()
```

In cases where this default is not correct only the `path_index_json` needs to 
be set to the correct path/url as shown below: 

```{r eval = FALSE}
## Upload new index.json to algolia, calling algoliar::create_config() required!
algoliar::algolia_post_batch(algoliar::create_config("mypath/index.json"))

```

Using the R package **algoliar** now automates the formerly manual workflow, which 
is described in detail in the [documentation](https://sourcethemes.com/academic/docs/search/#algolia) of the Hugo theme Academic.


## Other API calls

### Get

```{r eval = FALSE}
algoliar::algolia_get(config)

```

### Content

Content of "index.json" at [Algolia](https://algolia.com) as data.frame.

```{r eval = FALSE}
algoliar::algolia_content(config)
```


## Delete Index

For completly deleting an Algolia "index_name" run: 

```{r eval = FALSE}
algoliar::algolia_delete_index(config)
```

This means that it needs to be created manually again from the Algolia dashboard, 
since a creation method is not implemented in the R Package
