import{K as S,a7 as C,d as T,u as I,r as k,z as V,e as l,f as s,h as m,j as o,s as b,g as t,k as v,w,F as q,H as z,X as A,l as D,n as d,t as u,au as E,av as j,aw as B}from"./index-a0da86f0.js";import{I as f}from"./iconify-56cbf3ff.js";import{_ as F}from"./_plugin-vue_export-helper-c27b6911.js";const $=async g=>{var h,p,_;try{return{success:!0,data:((h=(await S.post("/jingrow/embedding/batch",{texts:g},{headers:C(),withCredentials:!0})).data)==null?void 0:h.data)||[]}}catch(r){return console.error("调用 Embedding API 异常:",r),{success:!1,message:((_=(p=r.response)==null?void 0:p.data)==null?void 0:_.detail)||r.message||"调用API失败"}}},M=async(g,h="knowledge_base",p=10,_=.7)=>{var r,n,i;try{return{success:!0,data:((r=(await S.post("/jingrow/embedding/search",{collection_name:h,query_vector:g,limit:p,score_threshold:_},{headers:C(),withCredentials:!0})).data)==null?void 0:r.data)||[]}}catch(y){return console.error("向量搜索失败:",y),{success:!1,message:((i=(n=y.response)==null?void 0:n.data)==null?void 0:i.detail)||y.message||"搜索失败"}}},P=async(g,h="knowledge_base",p=10,_=.7)=>{var r,n;try{const i=await $([g]);return!i.success||!((n=(r=i.data)==null?void 0:r[0])!=null&&n.embedding)?{success:!1,message:"Text to vector conversion failed"}:await M(i.data[0].embedding,h,p,_)}catch(i){return{success:!1,message:i.message||""}}},H={class:"search-results"},K={class:"search-header"},L={class:"search-info"},O={class:"search-title"},U={key:0,class:"search-subtitle"},X={key:1,class:"search-subtitle"},G={key:0,class:"loading-container"},J={class:"loading-text"},W={key:1,class:"results-container"},Y={class:"results-grid"},Z=["onClick"],Q={class:"result-header"},ee={class:"result-meta"},se={class:"result-type"},te={class:"result-score"},ae={class:"result-title"},oe={class:"result-content"},re={key:0,class:"result-summary"},ce={key:1,class:"result-tags"},ne={class:"result-footer"},ie={key:0,class:"result-date"},le={key:2,class:"empty-state"},de={class:"empty-icon"},ue={class:"empty-title"},_e={class:"empty-description"},he={key:3,class:"initial-state"},pe={class:"initial-icon"},ge={class:"initial-title"},ye={class:"initial-description"},me=T({__name:"SearchResults",setup(g){const h=A(),p=D(),_=I(),r=k(""),n=k([]),i=k(!1),y=async e=>{if(!e.trim()){n.value=[];return}i.value=!0;try{const a=await P(e,"knowledge_base",20,.5);a.success&&a.data?n.value=a.data:(_.error(a.message||u("Search failed")),n.value=[])}catch(a){console.error("搜索错误:",a),_.error(u("An error occurred during search")),n.value=[]}finally{i.value=!1}};V(()=>h.query.q,e=>{e&&typeof e=="string"&&(r.value=e,y(e))},{immediate:!0});const x=e=>{const{pagetype:a,name:c}=e.payload;a&&c&&p.push(`/app/${a}/${c}`)},N=(e,a)=>e?e.length<=a?e:e.substring(0,a)+"...":"",R=e=>{try{const a=new Date(e);return B.value==="zh-CN"?a.toISOString().split("T")[0]:a.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}catch{return e}};return(e,a)=>(d(),l("div",H,[s("div",K,[s("div",L,[s("h1",O,[m(o(f),{icon:"tabler:search",class:"title-icon"}),b(" "+t(o(u)("Search Results")),1)]),r.value?(d(),l("p",U,t(o(u)("Search keyword"))+': "'+t(r.value)+'" ',1)):v("",!0),!i.value&&n.value.length>0?(d(),l("p",X,t(o(u)("Found"))+" "+t(n.value.length)+" "+t(o(u)("relevant results")),1)):v("",!0)])]),i.value?(d(),l("div",G,[m(o(E),{size:"large"},{default:w(()=>[s("div",J,t(o(u)("Searching...")),1)]),_:1})])):n.value.length>0?(d(),l("div",W,[s("div",Y,[(d(!0),l(q,null,z(n.value,c=>(d(),l("div",{key:c.id,class:"result-card",onClick:ve=>x(c)},[s("div",Q,[s("div",ee,[s("span",se,t(c.payload.pagetype),1),s("span",te,t(o(u)("Similarity"))+": "+t(Math.round(c.score*100))+"%",1)]),s("div",ae,t(c.payload.title||c.payload.name),1)]),s("div",oe,[c.payload.content?(d(),l("p",re,t(N(c.payload.content,200)),1)):v("",!0),c.payload.category?(d(),l("div",ce,[m(o(j),{size:"small",type:"info"},{default:w(()=>[b(t(c.payload.category),1)]),_:2},1024)])):v("",!0)]),s("div",ne,[c.payload.modified?(d(),l("span",ie,t(R(c.payload.modified)),1)):v("",!0),m(o(f),{icon:"tabler:arrow-right",class:"result-arrow"})])],8,Z))),128))])])):!i.value&&r.value?(d(),l("div",le,[s("div",de,[m(o(f),{icon:"tabler:search-off"})]),s("h3",ue,t(o(u)("No relevant results found")),1),s("p",_e,t(o(u)("Try using different keywords or check spelling")),1)])):(d(),l("div",he,[s("div",pe,[m(o(f),{icon:"tabler:search"})]),s("h3",ge,t(o(u)("Start searching")),1),s("p",ye,t(o(u)("Enter keywords in the search box above to start searching")),1)]))]))}});const we=F(me,[["__scopeId","data-v-c8cd1ae1"]]);export{we as default};
