JSPWiki 支援附件檔案內容搜尋

2021-09-01 10:35:02 字數 1926 閱讀 1506

最近專案組要搭乙個wiki,經過篩選我們決定使用jspwiki(網上有大量的分析),待搭完以後,發現他不支援附件檔案內容搜尋,也就是說,如果這篇wiki中上傳了一些doc,xls等檔案是不能被搜尋到的,但是在jspwiki.properties配置中有如下配置:

jspwiki.searchprovider =lucenesearchprovider

jspwiki.lucene.analyzer = org.apache.lucene.analysis.standard.standardanalyzer

也就是jspwiki也是用lucene來做檢索的,於是下了他的原始碼,看了下這個類com.ecyrd.jspwiki.search.lucenesearchprovider,發現了如下方法:

protected string getattachmentcontent( attachment att )

catch (providerexception e)

catch (ioexception e)

} ......

於是決定給這個類動動手術,新增點功能讓它可以支援doc和xls, 新增了如下**在下面(office 2003到2007,檔案格式不同,分開來寫了),然後重新打包(打好的jar,我放在附件裡),啟動jspwiki, 實驗了一下,word 和 excel的檔案可以被查出來了。

注意的是,這個類的作用是,在附件檔案上傳,用lucene建立了索引,所以實驗的話,一定要重新上傳檔案,在改這個class之前上傳的檔案時沒有用的。

......       

else if(filename.endswith(".doc")) catch (exception e) finally

catch (ioexception e)

} }}

else if(filename.endswith(".docx")) catch (exception e) finally

catch (ioexception e)

} }}

else if(filename.endswith(".xls"))

for (int j = 0; j < sheet.getphysicalnumberofrows(); j++)

for (int k = 0; k < row.getlastcellnum(); k++)

}

}string s = sb.tostring();

log.debug("extracted text: " + s + " from attachment: " + filename);

return s;

} catch (exception e) finally

catch (ioexception e)

} }}

else if(filename.endswith(".xlsx"))

for (int j = 0; j < sheet.getphysicalnumberofrows(); j++)

for (int k = 0; k < row.getlastcellnum(); k++)

}

}string s = sb.tostring();

log.debug("extracted text: " + s + " from attachment: " + filename);

return s;

} catch (exception e) finally

catch (ioexception e)

}

}}

......

附件 檔案上傳

在前一篇文獻中介紹的檔案上傳,主要是依賴外掛程式的方法實現使用,只是編碼一些伺服器裡面的內容。而今天要介紹的是用編寫的 實現檔案上傳功能,上傳檔案的原理基本一致,只是需要編寫的 相對複雜一點。getattachmentfile 改變事件 getattachmentfile change functi...

讀取上傳附件的內容與手動上傳附件

上圖中的截圖是el upload元件上傳附件後返回的內容,其中raw欄位的值便是檔案的資訊,如果我們想要讀取檔案中的具體資訊,用以下方式 1 let reader new filereader 2 reader.readastext file.raw 以字串的格式讀取檔案 3 reader.onlo...

C 傳送郵件小程式(支援群發,附件)

在這裡,主要使用了system.web.mail命名空間下的類,具體 如下 先新建win專案,再複製 using system using system.drawing using system.collections using system.componentmodel using system...