锘??xml version="1.0" encoding="utf-8" standalone="yes"?>九九九九久久久久,欧美一区二区三区不卡,亚洲一区二区视频在线http://www.aygfsteel.com/xuyan5971/category/41265.htmlzh-cnWed, 12 Aug 2009 09:52:29 GMTWed, 12 Aug 2009 09:52:29 GMT60lucene_鏍規嵁绱㈠紩鎼滅儲鏂囦歡http://www.aygfsteel.com/xuyan5971/archive/2009/08/12/290862.htmlR99R99Wed, 12 Aug 2009 08:59:00 GMThttp://www.aygfsteel.com/xuyan5971/archive/2009/08/12/290862.htmlhttp://www.aygfsteel.com/xuyan5971/comments/290862.htmlhttp://www.aygfsteel.com/xuyan5971/archive/2009/08/12/290862.html#Feedback0http://www.aygfsteel.com/xuyan5971/comments/commentRss/290862.htmlhttp://www.aygfsteel.com/xuyan5971/services/trackbacks/290862.htmlpackage org.apache.lucene.demo;

/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Date;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.FilterIndexReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.HitCollector;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.Searcher;
import org.apache.lucene.search.TopDocCollector;

/** Simple command-line based search demo. */
public class SearchFiles {

  /** Use the norms from one field for all fields.  Norms are read into memory,
   * using a byte of memory per document per searched field.  This can cause
   * search of large collections with a large number of fields to run out of
   * memory.  If all of the fields contain only a single token, then the norms
   * are all identical, then single norm vector may be shared. */
  private static class OneNormsReader extends FilterIndexReader {
    private String field;

    public OneNormsReader(IndexReader in, String field) {
      super(in);
      this.field = field;
    }

    public byte[] norms(String field) throws IOException {
      return in.norms(this.field);
    }
  }

  private SearchFiles() {}

  /** Simple command-line based search demo. */
  public static void main(String[] args) throws Exception {
    String index = "index";
    String field = "content";
    boolean multipleFields = true;
    IndexReader reader = IndexReader.open(index);//IndexReader 鏍規嵁 index 鎸囧畾鐨勮礬寰?璁塊棶绱㈠紩錛屾壂鎻忕儲寮曘?br />     Searcher searcher = new IndexSearcher(reader);
    Analyzer analyzer = new StandardAnalyzer();
    BufferedReader in =new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
    while (true) {
   System.out.println("Enter query: ");
   String line = in.readLine();
   if (line == null || line.length() == -1)
    break;
   line = line.trim();
   if (line.length() == 0)
    break;
   if (!multipleFields) {
    QueryParser parser = new QueryParser(field, analyzer);
    Query query = parser.parse(field);// 鏍規嵁鎸囧畾鐨勫崟涓猣ield鏌ヨ
    parser.setDefaultOperator(parser.OR_OPERATOR.OR);
    //澶氫釜瀛楃涓蹭互絀烘牸浠芥牸鏃訛紝OR  : a b  鍚湁a鎴朾鍧囧彲銆?br />     //AND   a b 蹇呴』鍚湁 a鍜宐銆?br />     doPagingSearch(searcher, query);
    
   } else {

    String[] fields = new String[2];
    fields[0] = "contents";
    fields[1] = "name";
    BooleanClause.Occur[] flags = new BooleanClause.Occur[] {
      BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD };
    //鏍規嵁澶氫釜field鏌ヨ鏃躲俿hould,should鏌ヨ瀛楁鍦?name鎴栨槸contents浠諱綍涓涓腑錛屽潎鍋氫負涓鏉¤褰曡繑鍥炪?br />     //must,must .蹇呴』 鍗沖湪 name 涓紝鍙堝湪contents 涓?br />     Query query = MultiFieldQueryParser.parse(line, fields, flags,
      analyzer);
    doPagingSearch(searcher, query);
   }
  }
    reader.close();
  }
 
  /**
   * This method uses a custom HitCollector implementation which simply prints out
   * the docId and score of every matching document.
   *
   *  This simulates the streaming search use case, where all hits are supposed to
   *  be processed, regardless of their relevance.
   */

  public static void doPagingSearch( Searcher searcher, Query query) throws IOException {
 
    // Collect enough docs to show 5 pages
    TopDocCollector collector = new TopDocCollector(20);//鏈澶氱粨鏋滈泦涓暟銆?br />     searcher.search(query, collector);
    ScoreDoc[] hits = collector.topDocs().scoreDocs;
    int numTotalHits = collector.getTotalHits();//鎼滅儲鍒扮殑絎﹀悎鏉′歡鐨勮褰曟繪潯鏁般?br />     System.out.println(numTotalHits + " total matching documents");

    for(int i=0;i<numTotalHits;i++){
        Document doc = searcher.doc(hits[i].doc);
        System.out.println("path.."+doc.get("path"));
        System.out.println("modified.."+doc.get("modified"));
        System.out.println("name.."+doc.get("name"));
        System.out.println("parent"+doc.get("parent"));
        System.out.println("content..."+doc.get("content"));
    }
  }
}



R99 2009-08-12 16:59 鍙戣〃璇勮
]]>
lucence_瀵規枃浠跺緩绔嬬儲寮?/title><link>http://www.aygfsteel.com/xuyan5971/archive/2009/08/12/290837.html</link><dc:creator>R99</dc:creator><author>R99</author><pubDate>Wed, 12 Aug 2009 07:38:00 GMT</pubDate><guid>http://www.aygfsteel.com/xuyan5971/archive/2009/08/12/290837.html</guid><wfw:comment>http://www.aygfsteel.com/xuyan5971/comments/290837.html</wfw:comment><comments>http://www.aygfsteel.com/xuyan5971/archive/2009/08/12/290837.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/xuyan5971/comments/commentRss/290837.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/xuyan5971/services/trackbacks/290837.html</trackback:ping><description><![CDATA[<p><font style="background-color: #cce8cf">package org.apache.lucene.demo;</font></p> <p><font style="background-color: #cce8cf">/**<br />  * Licensed to the Apache Software Foundation (ASF) under one or more<br />  * contributor license agreements.  See the NOTICE file distributed with<br />  * this work for additional information regarding copyright ownership.<br />  * The ASF licenses this file to You under the Apache License, Version 2.0<br />  * (the "License"); you may not use this file except in compliance with<br />  * the License.  You may obtain a copy of the License at<br />  *<br />  *     http://www.apache.org/licenses/LICENSE-2.0<br />  *<br />  * Unless required by applicable law or agreed to in writing, software<br />  * distributed under the License is distributed on an "AS IS" BASIS,<br />  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br />  * See the License for the specific language governing permissions and<br />  * limitations under the License.<br />  */</font></p> <p><font style="background-color: #cce8cf">import org.apache.lucene.analysis.standard.StandardAnalyzer;<br /> import org.apache.lucene.index.IndexWriter;</font></p> <p><font style="background-color: #cce8cf">import java.io.File;<br /> import java.io.FileNotFoundException;<br /> import java.io.IOException;<br /> import java.util.Date;</font></p> <p><font style="background-color: #cce8cf">/** Index all text files under a directory. */<br /> public class IndexFiles {<br />   <br />   private IndexFiles() {}</font></p> <p><font style="background-color: #cce8cf">  static final File INDEX_DIR = new File("index");//绱㈠紩姝㈠綍銆傚緩鍦ㄥ綋鍓嶇洰褰曠殑/index涓?br />   <br />   /** Index all text files under a directory. */<br />   public static void main(String[] args) {//args[0] 鏂囦歡璺緞.  main 鏂規硶錛氬args[0]鎸囧畾鐨勬枃浠惰礬寰勪笅鐨勬墍鏈夋枃浠跺緩绔嬬儲寮曘?br />   final File docDir = new File(args[0]);<br />   if (!docDir.exists() || !docDir.canRead()) {<br />    System.out .println("Document directory '" + docDir.getAbsolutePath() + "' does not exist or is not readable, please check the path");<br />    System.exit(1);<br />   }<br />     <br />     Date start = new Date();<br />     try {<br />    IndexWriter writer = new IndexWriter(INDEX_DIR, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);<br />    //IndexWriter璐熻矗鍒涘緩鍜岀淮鎶ょ儲寮?br />    //IndexWriter(String path, Analyzer a, boolean create, IndexWriter.MaxFieldLength mfl)<br />    //path:璺緞 Analyzer:鏂囨湰鍒嗘瀽鍣?nbsp; create:鏄惁鍒涘緩鏂扮儲寮?nbsp; mfl 鏈澶ield鏁伴噺<br />    System.out.println("Indexing to directory '" + INDEX_DIR + "'...");<br />    indexDocs(writer, docDir);<br />    System.out.println("Optimizing...");<br />    writer.optimize();//浼樺寲绱㈠紩<br />    writer.close();//鍏抽棴<br />    Date end = new Date();<br />    System.out.println(end.getTime() - start.getTime() + " total milliseconds");<br />   } catch (IOException e) {<br />    System.out.println(" caught a " + e.getClass()<br />      + "\n with message: " + e.getMessage());<br />   }<br />   }</font></p> <p><font style="background-color: #cce8cf">  static void indexDocs(IndexWriter writer, File file) throws IOException {<br />   // do not try to index files that cannot be read<br />   if (file.canRead()) {<br />    if (file.isDirectory()) {<br />     String[] files = file.list();<br />     // an IO error could occur<br />     if (files != null) {<br />      for (int i = 0; i < files.length; i++) {<br />       indexDocs(writer, new File(file, files[i]));<br />      }<br />     }<br />    } else {<br />     System.out.println("adding " + file);<br />     try {<br />      writer.addDocument(FileDocument.Document(file));<br />     }<br />     // at least on windows, some temporary files raise this<br />     // exception with an "access denied" message<br />     // checking if the file can be read doesn't help<br />     catch (FileNotFoundException fnfe) {<br />      ;<br />     }<br />    }<br />   }<br />  }<br /> }<br /> <br /> <br /> <br /> </p> <p><font style="background-color: #cce8cf">package org.apache.lucene.demo;</font></p> <p><font style="background-color: #cce8cf">/**<br />  * Licensed to the Apache Software Foundation (ASF) under one or more<br />  * contributor license agreements.  See the NOTICE file distributed with<br />  * this work for additional information regarding copyright ownership.<br />  * The ASF licenses this file to You under the Apache License, Version 2.0<br />  * (the "License"); you may not use this file except in compliance with<br />  * the License.  You may obtain a copy of the License at<br />  *<br />  *     http://www.apache.org/licenses/LICENSE-2.0<br />  *<br />  * Unless required by applicable law or agreed to in writing, software<br />  * distributed under the License is distributed on an "AS IS" BASIS,<br />  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br />  * See the License for the specific language governing permissions and<br />  * limitations under the License.<br />  */</font></p> <p><font style="background-color: #cce8cf">import java.io.File;<br /> import java.io.FileReader;</font></p> <p><font style="background-color: #cce8cf">import org.apache.lucene.document.DateTools;<br /> import org.apache.lucene.document.Document;<br /> import org.apache.lucene.document.Field;</font></p> <p><font style="background-color: #cce8cf">/** A utility for making Lucene Documents from a File. */</font></p> <p><font style="background-color: #cce8cf">public class FileDocument {</font></p> <p><font style="background-color: #cce8cf">  public static Document Document(File f)<br />        throws java.io.FileNotFoundException {<br />   <br />     // make a new, empty document<br />     Document doc = new Document();<br />     <br />     doc.add(new Field("contents", new FileReader(f)));<br />     doc.add(new Field("path", f.getPath(), Field.Store.YES, Field.Index.NOT_ANALYZED));<br />     doc.add(new Field("modified", DateTools.timeToString(f.lastModified(), DateTools.Resolution.MINUTE),Field.Store.YES, Field.Index.ANALYZED));<br />     doc.add(new Field("name",f.getName(),Field.Store.YES,Field.Index.NOT_ANALYZED));<br />     //Field </font></p> <p><font style="background-color: #cce8cf">    // return the document<br />     return doc;<br />   }</font></p> <p><font style="background-color: #cce8cf">  private FileDocument() {}<br /> }<br />     <br /> </font></p> <p><br /> </font></p> <img src ="http://www.aygfsteel.com/xuyan5971/aggbug/290837.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/xuyan5971/" target="_blank">R99</a> 2009-08-12 15:38 <a href="http://www.aygfsteel.com/xuyan5971/archive/2009/08/12/290837.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> 主站蜘蛛池模板: <a href="http://" target="_blank">五河县</a>| <a href="http://" target="_blank">彰化县</a>| <a href="http://" target="_blank">扶绥县</a>| <a href="http://" target="_blank">无为县</a>| <a href="http://" target="_blank">牡丹江市</a>| <a href="http://" target="_blank">鄂伦春自治旗</a>| <a href="http://" target="_blank">巴塘县</a>| <a href="http://" target="_blank">都安</a>| <a href="http://" target="_blank">焦作市</a>| <a href="http://" target="_blank">紫金县</a>| <a href="http://" target="_blank">南川市</a>| <a href="http://" target="_blank">图片</a>| <a href="http://" target="_blank">屏南县</a>| <a href="http://" target="_blank">武宁县</a>| <a href="http://" target="_blank">阳谷县</a>| <a href="http://" target="_blank">蕉岭县</a>| <a href="http://" target="_blank">娱乐</a>| <a href="http://" target="_blank">北京市</a>| <a href="http://" target="_blank">托克托县</a>| <a href="http://" target="_blank">广昌县</a>| <a href="http://" target="_blank">扶绥县</a>| <a href="http://" target="_blank">婺源县</a>| <a href="http://" target="_blank">贵德县</a>| <a href="http://" target="_blank">精河县</a>| <a href="http://" target="_blank">淳化县</a>| <a href="http://" target="_blank">安义县</a>| <a href="http://" target="_blank">察雅县</a>| <a href="http://" target="_blank">正阳县</a>| <a href="http://" target="_blank">永宁县</a>| <a href="http://" target="_blank">海口市</a>| <a href="http://" target="_blank">格尔木市</a>| <a href="http://" target="_blank">洪湖市</a>| <a href="http://" target="_blank">富平县</a>| <a href="http://" target="_blank">阜城县</a>| <a href="http://" target="_blank">恩施市</a>| <a href="http://" target="_blank">科尔</a>| <a href="http://" target="_blank">庆元县</a>| <a href="http://" target="_blank">合江县</a>| <a href="http://" target="_blank">娄烦县</a>| <a href="http://" target="_blank">肥乡县</a>| <a href="http://" target="_blank">龙游县</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>