add localstorage to search type

This commit is contained in:
charlene tau express 2025-03-06 15:02:14 +08:00
parent 713443a74e
commit cd5a93fb8f
6 changed files with 49 additions and 13 deletions

View File

@ -27,4 +27,17 @@ server {
return 204; return 204;
} }
} }
location /recommend {
proxy_pass https://192.168.99.121; # Forward request to backend
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Ensure query parameters are preserved
proxy_pass_request_body on;
proxy_pass_request_headers on;
proxy_set_header Connection "";
}
} }

View File

@ -14,7 +14,7 @@
<div class="mt-[20px]"> <div class="mt-[20px]">
<label for="searchType" class="block text-sm !font-bold">Search Type</label> <label for="searchType" class="block text-sm !font-bold">Search Type</label>
<select v-model="selectedSearchType" id="searchType" class="mt-4 p-[10px] block w-full bg-[#1a1a1a] rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200"> <select v-model="selectedSearchType" @change="saveSearchType" id="searchType" class="mt-4 p-[10px] block w-full bg-[#1a1a1a] rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200">
<option v-for="option in searchTypes" :key="option" :value="option"> <option v-for="option in searchTypes" :key="option" :value="option">
{{ option }} {{ option }}
</option> </option>
@ -49,7 +49,7 @@
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {ref} from "vue"; import {ref, onMounted} from "vue";
import { useSearchStore } from "@/stores/searchStore"; import { useSearchStore } from "@/stores/searchStore";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
@ -61,10 +61,17 @@ const searchTypes = ref(["precise","associative","proximity","semantic"])
const searchQuery = ref("") const searchQuery = ref("")
const pageNumber = ref() const pageNumber = ref()
const pageSize = ref() const pageSize = ref()
onMounted(() => {
const savedType = localStorage.getItem("searchType");
if (savedType) {
selectedSearchType.value = savedType;
}
});
const searchStore = useSearchStore(); const searchStore = useSearchStore();
const saveSearchType = () => {
localStorage.setItem("searchType", selectedSearchType.value);
};
const sendRequest = async()=>{ const sendRequest = async()=>{
searchStore.searchParams = { searchStore.searchParams = {
query: searchQuery.value, query: searchQuery.value,
@ -72,7 +79,7 @@ const sendRequest = async()=>{
// page_num: pageNumber.value, // page_num: pageNumber.value,
// page_size: pageSize.value // page_size: pageSize.value
}; };
//console.log("searchStore: ", searchStore.searchParams)
router.push("/table"); router.push("/table");
} }
</script> </script>

View File

@ -10,7 +10,7 @@
<button @click="goToSearchPage" class="btn rounded-[10px] bg-[#0000FF] text-[white]">Back To Search Page</button> <button @click="goToSearchPage" class="btn rounded-[10px] bg-[#0000FF] text-[white]">Back To Search Page</button>
</div> </div>
</div> </div>
<div v-if="responseData" class="pt-[0px] h-[90%] w-[100%] border border-[blue] overflow-scroll"> <div v-if="!noData" class="pt-[0px] h-[90%] w-[100%] border border-[blue] overflow-scroll">
<table class="table table-pin-rows border w-full"> <table class="table table-pin-rows border w-full">
<thead class=""> <thead class="">
<!-- <tr class=""> --> <!-- <tr class=""> -->
@ -40,11 +40,14 @@ import { useSearchStore } from "@/stores/searchStore";
import {fetchData} from "@/utils/api.ts" import {fetchData} from "@/utils/api.ts"
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
const searchStore = useSearchStore(); const searchStore = useSearchStore();
// interface ApiResponse {
const responseData = ref("") // data: any[]; // Adjust this type according to your API response
// }
const responseData = ref<any>({ data: [] })
const searchWhat = ref(searchStore.searchParams.query) const searchWhat = ref(searchStore.searchParams.query)
const query={...searchStore.searchParams} const query={...searchStore.searchParams}
const noData=ref(false)
const keys_of_a_data=ref<any[]>() const keys_of_a_data=ref<any[]>()
@ -64,14 +67,15 @@ onMounted(()=>{
} }
fetchData("/search",requestType,query).then(response =>{ fetchData("/search",requestType,query).then(response =>{
if (response.data.length===0){ if (response.data.length===0){
noData.value=true
// responseData.value={}
responseData.value="" console.log("temporary")
} }
else { else {
noData.value=false
responseData.value = response responseData.value = response
if(requestType==="POST"){ if(requestType==="POST"){

View File

@ -18,7 +18,12 @@ export const fetchData = async(endpoints="", requestType="GET", requestBody:Reco
let response; let response;
if (requestBody?.search_type==="semantic"){ if (requestBody?.search_type==="semantic"){
response = await fetch("/recommend", options) const params = new URLSearchParams({
clause: requestBody?.query
}).toString();
response = await fetch(`/recommend?${params}`, options)
} }
else { else {

View File

@ -3,7 +3,7 @@ import InputFieldCard from '@/components/InputFieldCard.vue'
</script> </script>
<template> <template>
<main class="flex place-content-center p-4 h-[100%]"> <main class="flex place-content-center p-4 ">
<InputFieldCard/> <InputFieldCard/>
</main> </main>
</template> </template>

View File

@ -17,6 +17,13 @@ export default defineConfig({
target: "https://192.168.99.121", target: "https://192.168.99.121",
changeOrigin: true, changeOrigin: true,
secure: false, // Ignores SSL certificate issues secure: false, // Ignores SSL certificate issues
// configure: (proxy) => {
// proxy.on('proxyReq', (proxyReq, req) => {
// console.log('Incoming request URL:', req.url); // Logs request URL
// console.log('Final URL sent to backend:', proxyReq.path); // Logs what Vite sends
// console.log('Final URL sent to backend:', proxyReq)
// });
// }
}, },
}, },
}, },