---
title: "Introduction to finna"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Introduction to finna}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

# Introduction


[Finna](https://www.finna.fi/) is a Finnish national search service that provides access to the collections of Finnish museums, libraries, and archives. It is maintained by the National Library of Finland in collaboration with other cultural and scientific institutions. Finna allows users to search and explore a wide range of resources, including books, images, maps, artifacts, and digital content from various institutions across Finland.

This vignette provides an overview of how to use the finna package.

To make a simple search use the following code.

**N.B** In the search_finna() default limit of 100 records is being used. Specify 'limit' argument for more records.


```{r message = FALSE, warning = FALSE}
library(finna)
record <- search_finna("sibelius")
print(record)
```

## Searching as subject

```{r message = FALSE, warning = FALSE}
library(finna)
record <- search_finna(query = '"orkesterimusiikki"', type = "Subject", lng = "en-gb")
print(record)
```
## Bulk search 
 
 I we need a bulk download we use
`search_finna("sibelius", limit = Inf)` where we add the term `limit = Inf`.

## Search phrase examples
```{r message = FALSE, warning = FALSE}
library(finna)
phrase <- search_finna("bicycle")
print(phrase)
```


### Search operators + and !-
In addition to the most common Boolean operators (AND, OR, NOT), Finna uses the + and !- operators.

### +

The + sign indicates that the search term must be found in every search result.

For example, if you are looking for material that must feature economics and which may also feature Keynes:

```{r message = FALSE, warning = FALSE}
library(finna)
search_oper <- search_finna("+economics Keynes”)")
print(search_oper)
```

### !-

The symbols !- remove any search results which feature the search term following the operator !-.

For example, if you want to find material that feature the term economics but not the term Keynes:


```{r message = FALSE, warning = FALSE}
library(finna)
search_oper <- search_finna("economics !-Keynes”)")
print(search_oper)
```

#### NB! The !- operator cannot be used in single-word searches.

For example, the following search will yield no results:

```{r message = FALSE, warning = FALSE}
library(finna)
search_oper <- search_finna("!-economics”)")
print(search_oper)
```

### Fine-tuning your search

#### Fuzzy search

Fuzzy search will also yield results that feature words which are similar to your search term.

The search operator ~ will perform a fuzzy search when it is used as the final character of a single-word search.

For example, a fuzzy search with the word roam will also return results with the words foam and roams.

```{r message = FALSE, warning = FALSE}
fuzzy_search <- search_finna("roam~")
print(fuzzy_search)
```

#### Proximity search

Proximity searches look for material in which the search terms are within a 
specified distance, but not necessarily one after the other.

```{r message = FALSE, warning = FALSE}
fuzzy_search <- search_finna("economics Keynes~10")
print(fuzzy_search)
```

## Advanced search: to see available online


```{r message = FALSE, warning = FALSE}
record <- search_finna("sibelius", filters = c("free_online_boolean:1"))
print(record)
```

### search image

```{r message = FALSE, warning = FALSE}
record <- search_finna("sibelius", filters = c('~media_type_str_mv:"0/image/"'))
print(record)
```

### Audio book

```{r message = FALSE, warning = FALSE}
record <- search_finna("sibelius", filters = c('~format:"1/Book/AudioBook/"'))
print(record)
```

### Year of manufacture

```{r message = FALSE, warning = FALSE}
record <- search_finna("sibelius", filters = c('search_daterange_mv:"overlap|[-5000 TO 5000]"'))
print(record)
```

### Search using Geofilter syntax (Geographical region)

```{r message = FALSE, warning = FALSE}
record <- search_finna("trump", filters = c('{!geofilt sfield=location_geo pt=61.663987171517796,24.17263895273209 d=212.53603751769646}'))
print(record)
```

### geofilter ouside of finland


```{r message = FALSE, warning = FALSE}
record <- search_finna("trump", filters = c('{!geofilt sfield=location_geo pt=39.3130504637139,-76.33021295070648 d=281.83790818401854}'))
print(record)
```

### Narrowing the search 

When narrowing search you can  use codes as a combination as follows

```{r message = FALSE, warning = FALSE}
record <- search_finna("trump", filters = c('{!geofilt sfield=location_geo pt=61.663987171517796,24.17263895273209 d=212.53603751769646},author_facet:"Häkkinen,Hannu"'))
print(record)
```


### specific search 

```{r message = FALSE, warning = FALSE}
record <- search_finna("era:'2010-luku'", filters = c('building:"0/3AMK/"'))

```

### search without removing duplication

In order to search data without removing duplication
example.

```{r message = FALSE, warning = FALSE}
record <- search_finna('era:"2010-luku"', filters = c('~building:"0/3AMK/"', 'finna.deduplication:"1"'))
print(record)
```
We can confirm this as follows by checking the count

```{r message = FALSE, warning = FALSE}
record <- search_finna('era:"2010-luku"', filters = c('~building:"0/3AMK/"', 'finna.deduplication:"1"'))
result_count <- attr(record, "result_count")
print(result_count)
```

Removing duplication can be done as follows

```{r message = FALSE, warning = FALSE}
record <- search_finna('era:"2010-luku"', filters = c('~building:"0/3AMK/"', 'finna.deduplication:"0"'))
print(record)
```

To confirm this we can check the count 

```{r message = FALSE, warning = FALSE}
record <- search_finna('era:"2010-luku"', filters = c('~building:"0/3AMK/"', 'finna.deduplication:"0"'))
result_count <- attr(record, "result_count")
print(result_count)
```

# Search Finna with multiple filters 
To find scholarly journals and digital repository materials regarding music 

```{r message = FALSE, warning = FALSE}
results <- search_finna(
  query = "musiikki OR taide OR tanssi OR teatteri",
  filters = c(
    '~hierarchy_parent_title:"Institutional Repository"',
    '~format_ext_str_mv:"1/Thesis/Gradu/"',
    '~format_ext_str_mv:"1/Thesis/Masters/"',
    '~format_ext_str_mv:"1/Thesis/MastersPolytechnic/"',
    '~format_ext_str_mv:"1/Thesis/Thesis/"',
    '~format_ext_str_mv:"1/Thesis/Licentiate/"',
    '~format_ext_str_mv:"0/OtherText/"',
    '~format_ext_str_mv:"0/Journal/"',
    '~format_ext_str_mv:"0/Book/"',
    'free_online_boolean:"1"'
  ),
  type = "AllFields",
  lng = "en-gb",
  prettyPrint = TRUE
)

# Print the results
print(results)
```
