Skip to content

Commit

Permalink
3.3.2: update gesis search api
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswilm committed Nov 30, 2017
1 parent 5c13da5 commit ecc2143
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 47 deletions.
111 changes: 65 additions & 46 deletions citation-api-import/static/js/es6_modules/citation-api-import/gesis.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {searchApiResultGesisTemplate} from "./templates"
import {
searchApiResultGesisTemplate
} from "./templates"

export class GesisSearcher {

Expand All @@ -18,55 +20,72 @@ export class GesisSearcher {

lookup(searchTerm) {

return fetch('https://search.gesis.org/searchengine', {
method: "POST",
body: {
"query": {
"bool": {
"must": [
let searchQuery = {
"query": {
"bool": {
"must": [{
"query_string": {
"query": searchTerm
}
}],
"should": [ // We only search types which make sense to cite.
{
"term": {
"type": "publication"
}
},
{
"term": {
"type": "research_data"
}
},
{
"query_string": {
"query": searchTerm
}
"term": {
"type": "instruments_tools"
}
},
{
"term": {
"type": "gesis_bib"
}
}
],
"should": [ // We only search types which make sense to cite.
{"term": {"type": "publication"}},
{"term": {"type": "research_data"}},
{"term": {"type": "instruments_tools"}},
{"term": {"type": "gesis_bib"}}
],
"minimum_should_match" : 1
}
}
}
}).then(
response => response.json()
).then(json => {
let items = json['hits']['hits'].map(hit => hit._source)
let searchEl = document.getElementById('bibimport-search-result-gesis')
if (!searchEl) {
// window was closed before result was ready.
return
}
if (items.length) {
searchEl.innerHTML = searchApiResultGesisTemplate({items})
} else {
searchEl.innerHTML = ''
],
"minimum_should_match": 1
}
}
this.bind()
})
}
}

getBibtex(id, type) {
fetch(`/proxy/citation-api-import/https://search.gesis.org/ajax/bibtex.php?type=${type}&docid=${id}&download=true`, {
method: "GET",
credentials: "same-origin"
return fetch(`https://search.gesis.org/searchengine?source=${encodeURI(JSON.stringify(searchQuery))}`, {
method: "GET"
}).then(
response => response.text()
).then(
bibtex => this.importer.importBibtex(bibtex)
)
}
response => response.json()
).then(json => {
let items = json['hits']['hits'].map(hit => hit._source)
let searchEl = document.getElementById('bibimport-search-result-gesis')
if (!searchEl) {
// window was closed before result was ready.
return
}
if (items.length) {
searchEl.innerHTML = searchApiResultGesisTemplate({
items
})
} else {
searchEl.innerHTML = ''
}
this.bind()
})
}

getBibtex(id, type) {
fetch(`/proxy/citation-api-import/https://search.gesis.org/ajax/bibtex.php?type=${type}&docid=${id}&download=true`, {
method: "GET",
credentials: "same-origin"
}).then(
response => response.text()
).then(
bibtex => this.importer.importBibtex(bibtex)
)
}

}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='fiduswriter-citation-api-import',
version='3.3.1',
version='3.3.2',
packages=find_packages(),
include_package_data=True,
license='AGPL License',
Expand Down

0 comments on commit ecc2143

Please sign in to comment.