小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Lucene-2.0學(xué)習(xí)文檔(2) - 企業(yè)應(yīng)用 - Java - JavaEye論壇

 ShangShujie 2009-03-18
接http://www./post/190334
IndexWriter(File path, Analyzer a, boolean create)
IndexWriter(String path, Analyzer a, boolean create)
可見構(gòu)造它需要一個(gè)索引文件目錄,一個(gè)分析器(一般用標(biāo)準(zhǔn)的這個(gè)),最后一個(gè)參數(shù)是標(biāo)識(shí)是否清空索引目錄
它有一些設(shè)置參數(shù)的功能如:設(shè)置Field的最大長度
看個(gè)例子:
[code]
public void IndexMaxField() throws IOException
{
        IndexWriter indexWriter= new IndexWriter("c:\\index",new StandardAnalyzer(),true);
        Document doc1 = new Document();
        doc1.add(new Field("name1","程序員之家",Field.Store.YES,Field.Index.TOKENIZED));
        Document doc2 = new Document();
        doc2.add(new Field("name2","Welcome to the Home of programers",Field.Store.YES,Field.Index.TOKENIZED));
        indexWriter.setMaxFieldLength(5);
        indexWriter.addDocument(doc1);
        indexWriter.setMaxFieldLength(3);
        indexWriter.addDocument(doc1);
        indexWriter.setMaxFieldLength(0);
        indexWriter.addDocument(doc2);
        indexWriter.setMaxFieldLength(3);
        indexWriter.addDocument(doc2);
        indexWriter.close();
}
public void SearcherMaxField() throws ParseException, IOException
{
        Query query = null;
        Hits hits = null;
        IndexSearcher indexSearcher= null;
        QueryParser queryParser= null;
        queryParser = new QueryParser("name1",new StandardAnalyzer());
        query = queryParser.parse("程序員");
        indexSearcher= new IndexSearcher("c:\\index");
        hits = indexSearcher.search(query);
        System.out.println("您搜的是:程序員");
        System.out.println("找到了"+hits.length()+"個(gè)結(jié)果");
        System.out.println("它們分別是:");
        for (int i = 0; i < hits.length(); i++)
        {
            Document doc = hits.doc(i);
            System.out.println(doc.get("name1"));
        }
        query = queryParser.parse("程序員之家");
        indexSearcher= new IndexSearcher("c:\\index");
        hits = indexSearcher.search(query);
        System.out.println("您搜的是:程序員之家");
        System.out.println("找到了"+hits.length()+"個(gè)結(jié)果");
        System.out.println("它們分別是:");
        for (int i = 0; i < hits.length(); i++)
        {
            Document doc = hits.doc(i);
            System.out.println(doc.get("name1"));
        }
        queryParser = new QueryParser("name2",new StandardAnalyzer());
        query = queryParser.parse("Welcome");
        indexSearcher= new IndexSearcher("c:\\index");
        hits = indexSearcher.search(query);
        System.out.println("您搜的是:Welcome");
        System.out.println("找到了"+hits.length()+"個(gè)結(jié)果");
        System.out.println("它們分別是:");
        for (int i = 0; i < hits.length(); i++)
        {
            Document doc = hits.doc(i);
            System.out.println(doc.get("name2"));
        }           
        query = queryParser.parse("the");
        indexSearcher= new IndexSearcher("c:\\index");
        hits = indexSearcher.search(query);
        System.out.println("您搜的是:the");
        System.out.println("找到了"+hits.length()+"個(gè)結(jié)果");
        System.out.println("它們分別是:");
        for (int i = 0; i < hits.length(); i++)
        {
            Document doc = hits.doc(i);
            System.out.println(doc.get("name2"));
        }
        query = queryParser.parse("home");
        indexSearcher= new IndexSearcher("c:\\index");
        hits = indexSearcher.search(query);
        System.out.println("您搜的是:home");
        System.out.println("找到了"+hits.length()+"個(gè)結(jié)果");
        System.out.println("它們分別是:");
        for (int i = 0; i < hits.length(); i++)
        {
            Document doc = hits.doc(i);
            System.out.println(doc.get("name2"));
        }
}
[/code]
它的運(yùn)行結(jié)果為:
總結(jié)一下:
1.設(shè)置Field的長度限制只是限制了搜索。如果用了Field.Store.YES的話還是會(huì)
全部被保存進(jìn)索引目錄里的。
2.為什么搜the沒有搜出來呢是因?yàn)閘ucene分析英文的時(shí)候不會(huì)搜索the to of 等無
用的詞(搜這些詞是無意義的)。
3.New StandardAnlayzer()對(duì)于英文的分詞是按空格和一些無用的詞,而中文呢是全部的單個(gè)
的字。
4.設(shè)置Field的最大長度是以0開頭和數(shù)組一樣。
程序員之家----------3--------程序員之
                                    0 1 2  3
Welcome to the home of programmers------3------Welcome to the home of programmers

                                                   0           1         2
大家還可以試一下別的,以便加深一下印象
(未完)

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請遵守用戶 評(píng)論公約

    類似文章 更多