# How the search is working 

## Search: Read for the indexed data

For the UI, we have the `search_ controller`  that have two actions `index` and `json_search`  the first is used for the search page and the latter for the jump-to-box concepts/classes page.

  
Both call the `/search`  endpoint of the API; which calls the `process_search` in the API search_controller.

  
`process_search`   is mostly sending the query to the search server (Solr) that is indexing all the values of classes (prefLabel, altLabel, ….) and properties.

  
The call to the search server is done with this line `LinkedData::Models::Class.search(query, params) ` , the search method is defined in Goo as a class method for all the models.

  

### Search SOLR query

The query is built using the search helper `get_term_search_query`


## Index data: Write data in the search server

In each submission process, we have two steps related to the indexation called `index_search` and `index_properties` .

  
Both have methods defined in the model `ontology_submission` ; for classes, the method is called `index` and `index_properties` for ontology properties. They are looping over the terms  (class or property) by page batches; 1000 at once. And index them by batch  using the Goo method `indexBatch` defined also as a class method on all the models.

  
  
The method `indexBatch` to know which attributes of the model to index; the model needs to define the abstract method `indexDoc`  that returns a Hash of (key, values) that will be indexed.

  
At the same time, all the indexed data are also saved in a CSV file, used as the CSV format of the submission downloadable next to the other formats(RDF, XRDF,…).

### Index classes terms

The model `Class`, defined the `indexDoc` method to index the following attributes:

* childCount
* parents
* ontologyId
* submissionAcronym
* submissionId
* ontologyType
* obsolete
* id
* prefLabel
* notation
* synonym
* definition
* cui
* semanticType
* property (unmapped properties values)
* propertyRaw (a JSON dump  of the unmapped properties)

  
here is an example of an index Class


```bash
"childCount":26,
"parents":["http://www.irit.fr/recherches/MELODI/ontologies/JardinagePlanteV1.owl#F_asteraceae",
          "http://www.irit.fr/recherches/MELODI/ontologies/JardinagePlanteV1.owl#Plante"],
"ontologyId":"http://data.bioontology.org/ontologies/OJP/submissions/2",
"submissionId":2,
"ontologyType":"ONTOLOGY",
"obsolete":false,
"id":"http://www.irit.fr/recherches/MELODI/ontologies/JardinagePlanteV1.owl#G_Ambrosia__2",
"prefLabel":"G_Ambrosia",
"prefLabelExact":"G_Ambrosia",
"prefLabelSuggest":"G_Ambrosia",
"prefLabelSuggestEdge":"G_Ambrosia",
"prefLabelSuggestNgram":"G_Ambrosia",
"property":["artemisiifolia",
          "diversifolia",
          "Hymenoclea",
          "Iva",
          "Ambrosia",
          "Franseria",
          "Gaertneria",
          "G_Ambrosia",
          "Thu Mar 06 20:00:13 CET 2014",
          "Thu Mar 06 20:00:12 CET 2014",
          "Software",
          "http://www.irit.fr/recherches/MELODI/ontologies/JardinagePlanteV1.owl#F_asteraceae",
          "http://www.w3.org/2002/07/owl#NamedIndividual",
          "http://www.w3.org/2002/07/owl#Class",
          "http://www.irit.fr/recherches/MELODI/ontologies/JardinagePlanteV1.owl#Genre_ambrosia"],
"propertyRaw":"{\"http://www.w3.org/2000/01/rdf-schema#label\":[\"artemisiifolia\",\"diversifolia\",\"Hymenoclea\",\"Iva\",\"Ambrosia\",\"Franseria\",\"Gaertneria\"],\"http://data.bioontology.org/metadata/prefixIRI\":[\"G_Ambrosia\"],\"http://data.bioontology.org/metadata/def/prefLabel\":[\"G_Ambrosia\"],\"http://purl.org/dc/terms/modified\":[\"Thu Mar 06 20:00:13 CET 2014\"],\"http://purl.org/dc/terms/created\":[\"Thu Mar 06 20:00:12 CET 2014\"],\"http://purl.org/dc/terms/creator\":[\"Software\"],\"http://www.w3.org/2000/01/rdf-schema#subClassOf\":[\"http://www.irit.fr/recherches/MELODI/ontologies/JardinagePlanteV1.owl#F_asteraceae\"],\"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\":[\"http://www.w3.org/2002/07/owl#NamedIndividual\",\"http://www.w3.org/2002/07/owl#Class\"],\"http://www.w3.org/2002/07/owl#aPourGenre\":[\"http://www.irit.fr/recherches/MELODI/ontologies/JardinagePlanteV1.owl#Genre_ambrosia\"]}",
"resource_id":"http://www.irit.fr/recherches/MELODI/ontologies/JardinagePlanteV1.owl#G_Ambrosia",
"provisional":false,
```

### Index properties terms

Same as classes for the most

---

**Documents**

- [💁‍♂️ Acknowledgments](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/acknowledgments-15GdRXLQdm)
- [📚Publications and references](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/publications-and-references-87tEoeoGKy)
- [🗽Terms & Conditions](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/terms-conditions-naDsDo2Zxq)
- [🧞‍♂️Metadata guidelines and recommendations](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/metadata-guidelines-and-recommendations-pOFbK9sIfp)
- [📜 AgroPortal Release Notes](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/agroportal-release-notes-btKjZk5tU2)
- [ 👩‍🚀 User Guide](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/user-guide-ZszoBwfjGF)
- [📎 API Documentation](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/api-documentation-kMCurGKD97)
- [🤖 Developer Documentation](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/developer-documentation-LhsrucqGTa)
- [🗃External Documentation](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/external-documentation-vNPQCdArrr)
- [AgroPortal infrastructure](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/agroportal-infrastructure-ietsAU4kPs)