adds local site data search
This commit is contained in:
parent
d0274a9ce2
commit
7e3481f0f1
|
@ -27,7 +27,7 @@ This file is part of ArciveList.
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { mapMutations } from 'vuex'
|
import { mapMutations, mapGetters } from 'vuex'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Search",
|
name: "Search",
|
||||||
|
@ -38,16 +38,21 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
search: function() {
|
search: function() {
|
||||||
|
if (this.search_text==="") {
|
||||||
|
return
|
||||||
|
}
|
||||||
console.log(this.search_text)
|
console.log(this.search_text)
|
||||||
this.setSearchText(this.search_text)
|
this.setSearchText(this.search_text)
|
||||||
|
var local_search_result = this.searchLocalSiteData()
|
||||||
var api_endpoint = '/api/collections/search?fulltext_search='
|
var api_endpoint = '/api/collections/search?fulltext_search='
|
||||||
var search_url = api_endpoint + this.search_text;
|
var search_url = api_endpoint + this.search_text;
|
||||||
var self = this;
|
var self = this;
|
||||||
axios.get(search_url, {
|
axios.get(search_url, {
|
||||||
})
|
})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
console.log(response.data)
|
//console.log(response.data)
|
||||||
self.setFilteredSites(response.data)
|
self.setFilteredSites(Object.assign({}, local_search_result, response.data))
|
||||||
|
//self.setFilteredSites(response.data)
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
@ -56,6 +61,10 @@ export default {
|
||||||
...mapMutations([
|
...mapMutations([
|
||||||
'setFilteredSites', 'setSearchText'
|
'setFilteredSites', 'setSearchText'
|
||||||
]),
|
]),
|
||||||
|
...mapGetters([
|
||||||
|
'searchLocalSiteData'
|
||||||
|
]),
|
||||||
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
29
src/store.js
29
src/store.js
|
@ -30,6 +30,7 @@ const store = new Vuex.Store({
|
||||||
state.page_count = state.page_count +1
|
state.page_count = state.page_count +1
|
||||||
},
|
},
|
||||||
setFilteredSites(state, filtered_site_ids) {
|
setFilteredSites(state, filtered_site_ids) {
|
||||||
|
console.log('filtered_site_ids')
|
||||||
console.log(filtered_site_ids)
|
console.log(filtered_site_ids)
|
||||||
var sites = []
|
var sites = []
|
||||||
for (const [site_id, weight] of Object.entries(filtered_site_ids)) {
|
for (const [site_id, weight] of Object.entries(filtered_site_ids)) {
|
||||||
|
@ -61,6 +62,34 @@ const store = new Vuex.Store({
|
||||||
getPageCount: state => {
|
getPageCount: state => {
|
||||||
return state.page_count
|
return state.page_count
|
||||||
},
|
},
|
||||||
|
searchLocalSiteData: state => {
|
||||||
|
var result = {}
|
||||||
|
if (state.search_text==="") {
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
for (let site in state.sites) {
|
||||||
|
var weight = 0
|
||||||
|
var found = state.sites[site].summary.toLowerCase().search(state.search_text.toLowerCase())
|
||||||
|
if (found != -1) {
|
||||||
|
weight = weight +1
|
||||||
|
}
|
||||||
|
var found = state.sites[site].collection.toLowerCase().search(state.search_text.toLowerCase())
|
||||||
|
if (found != -1) {
|
||||||
|
weight = weight +1
|
||||||
|
}
|
||||||
|
var found = state.sites[site].currator.toLowerCase().search(state.search_text.toLowerCase())
|
||||||
|
if (found != -1) {
|
||||||
|
weight = weight +1
|
||||||
|
}
|
||||||
|
if (weight > 0) {
|
||||||
|
var id = state.sites[site].id
|
||||||
|
result[id] = weight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('load search')
|
||||||
|
console.log(result)
|
||||||
|
return result
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue