Java-Android-jwebee
          Java-Android-jwebee
          對(duì)IT人來(lái)說(shuō),要成為一個(gè)優(yōu)秀的技術(shù)型管理者,除了需要具備扎實(shí)的技術(shù)基礎(chǔ)之外,還應(yīng)該培養(yǎng)良好的人際關(guān)系能力、談判與溝通技能、客戶關(guān)系與咨詢技能、商業(yè)頭腦和財(cái)務(wù)技能以及創(chuàng)新意識(shí),此外還要有巧妙的激勵(lì)技巧和化解沖突與解決突發(fā)問(wèn)題的能力.

          lucene實(shí)現(xiàn)搜索引擎的建立索引數(shù)據(jù)庫(kù),處理搜索結(jié)果.

          一,創(chuàng)建索引

          ?public boolean createIndex() throws IOException {
          ? //.......
          ??Directory fsDirectory = FSDirectory.getDirectory(Constant.INDEX_DIR, true);
          ??Analyzer analyzer =? new IK_CAnalyzer();//分析器
          ??IndexWriter indexWriter = new IndexWriter(fsDirectory, analyzer, true);
          ??for (int i = 0; i < htmls.length; i++) {
          ???String htmlPath = htmls[i].getAbsolutePath();
          ???if (htmlPath.endsWith(".html") || htmlPath.endsWith(".htm")) {
          ???//添加?Document
          ???addDocument(htmlPath, indexWriter);
          ???}
          ??}
          ??indexWriter.optimize();
          ??indexWriter.close();
          ?}
          二 ,添加?Document
          ?public void addDocument(String htmlPath, IndexWriter indexWriter) {
          ??HTMLDocParser htmlParser = new HTMLDocParser(htmlPath);
          ??String path = htmlParser.getPath();
          ??String title = htmlParser.getTitle();
          ??Reader content = htmlParser.getContent();
          ??LineNumberReader reader = new LineNumberReader(content);
          ??String snap = "";
          ??try {
          ???snap = reader.readLine();
          ???String tp = reader.readLine();
          ???if (snap.length() < 30 & tp != null) {
          ????snap = snap + tp;
          ???}
          ??} catch (IOException e1) {
          ???e1.printStackTrace();
          ??}
          ??Document document = new Document();
          ??document.add(new Field("path", path, Field.Store.YES, Field.Index.NO));//文件路徑
          ??document.add(new Field("title", title, Field.Store.YES,Field.Index.TOKENIZED));//文件標(biāo)題
          ??document.add(new Field("snap", snap, Field.Store.YES, Field.Index.NO));//快照
          ??document.add(new Field("content", content));//內(nèi)容
          ??try {
          ???indexWriter.addDocument(document);
          ??} catch (IOException e) {
          ???e.printStackTrace();
          ??}
          ?}
          三 ,顯示結(jié)果
          public List search() {
          ??List searchResult = new ArrayList();
          ??if (false == indexManager.ifIndexExist()) {
          ???try {
          ????if (false == indexManager.createIndex()) {
          ?????return searchResult;
          ????}
          ???} catch (IOException e) {
          ????e.printStackTrace();
          ????return searchResult;
          ???}
          ??}

          ??IndexSearcher indexSearcher = null;

          ??try {
          ???indexSearcher = new IndexSearcher(indexManager.getIndexDir());
          ??} catch (IOException ioe) {
          ???ioe.printStackTrace();
          ??}

          ??QueryParser queryParser = new QueryParser("content", analyzer);
          ??Query query = null;
          ??try {
          ???query = queryParser.parse(searchWord);
          ??} catch (ParseException e) {
          ???e.printStackTrace();
          ??}
          ??if (null != query && null != indexSearcher) {
          ???try {
          ????Hits hits = indexSearcher.search(query);
          ????for (int i = 0; i < hits.length(); i++) {
          ?????SearchResultBean resultBean = new SearchResultBean();
          ?????resultBean.setHtmlPath(hits.doc(i).get("path"));
          ?????resultBean.setHtmlTitle(hits.doc(i).get("title"));
          ?????resultBean.setHtmlSnap(hits.doc(i).get("snap"));
          ?????searchResult.add(resultBean);
          ????}
          ???} catch (IOException e) {
          ????e.printStackTrace();
          ???}
          ??}
          ??return searchResult;
          ?}

          ?

          myeclipse4.2 weblogic 9? 驗(yàn)證通過(guò)
          部署方法
          下載 lucene-test.rar
          修改web.xml啟動(dòng)參數(shù)dataDir,indexDir

          ?



          jwebee

          我的個(gè)人網(wǎng)站
          posted on 2007-05-28 15:32 周行 閱讀(2302) 評(píng)論(0)  編輯  收藏 所屬分類: IT技術(shù)
          Java-Android-jwebee
          主站蜘蛛池模板: 汝州市| 额尔古纳市| 巴青县| 靖宇县| 淳化县| 平陆县| 怀化市| 塘沽区| 伊春市| 迁西县| 呼玛县| 宜丰县| 罗定市| 东辽县| 凌海市| 德化县| 黎川县| 泰和县| 新野县| 芦溪县| 集贤县| 张北县| 沙雅县| 石景山区| 大邑县| 即墨市| 扶风县| 浮梁县| 庄浪县| 晋江市| 眉山市| 沙湾县| 清水河县| 田东县| 曲麻莱县| 南京市| 望江县| 衡山县| 区。| 思茅市| 大荔县|