lucene-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pitbull <trackstudio2...@gmail.com>
Subject Problem with search, when I rewriting index
Date Fri, 14 Jan 2011 10:16:33 GMT

I have simple code, It create index and rewrite data.
Code:
[code]
package client;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.*;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;

import java.io.File;

public class Lucene {
    private final static String path = "/home/pitbull/temp/lucene";

    public static void main(String[] args) throws Exception {
        write();
    }

    private static void write() throws Exception {
        String ts = "http://localhost/TrackStudiotrackstudio", or =
"http://localhost/OfficeRecoverytrackstudio";
        IndexWriter writerSCM = new IndexWriter(FSDirectory.open(new
File(path)), new StandardAnalyzer(Version.LUCENE_30), true,
IndexWriter.MaxFieldLength.UNLIMITED);
        Searcher searcher = new IndexSearcher(writerSCM.getReader());
        Document doc = getSCMlastCommitDocument(or, String.valueOf(11));
        search(searcher, or);
        writerSCM.addDocument(doc);
        writerSCM.commit();
        search(searcher, or);
        doc = getSCMlastCommitDocument(ts, String.valueOf(13));
        search(searcher, ts);
        writerSCM.addDocument(doc);
        writerSCM.commit();
        search(searcher, ts);
        writerSCM.close();        
        searcher.close();
    }

    private static void search(Searcher searcher, String lavelScm) throws
Exception {
        System.out.println("Search ... ");
        TopDocsCollector collector = TopFieldCollector.create(new Sort(new
SortField(null, SortField.DOC, true)), 100, false, false, false, false);
        Query query = new TermQuery(new Term("scmLastCommit", lavelScm));
        searcher.search(query, collector);
        ScoreDoc[] hits = collector.topDocs().scoreDocs;
        for (ScoreDoc hit : hits) {
            Document doc = searcher.doc(hit.doc);
            Long lastCommit = Long.parseLong(doc.get("lastCommit"));
            String scmUrl = doc.get("scmLastCommit").trim();
            System.out.println(lastCommit + " " + scmUrl);
        }
    }

    private static Document getSCMlastCommitDocument(String url, String
lastCommit) {
        Document doc = new Document();
        doc.add(new Field("scmLastCommit", url, Field.Store.YES,
Field.Index.NOT_ANALYZED_NO_NORMS));
        doc.add(new Field("lastCommit", lastCommit, Field.Store.YES,
Field.Index.NOT_ANALYZED_NO_NORMS));
        return doc;
    }
}
[/code]
When I rewrite term I can't search anything. What could be the problem?
I read documentation about NRT NearRealtimeSearch - Lucene-java Wiki. but
this can't help.
Thanks.
-- 
View this message in context: http://lucene.472066.n3.nabble.com/Problem-with-search-when-I-rewriting-index-tp2254574p2254574.html
Sent from the Lucene - General mailing list archive at Nabble.com.

Mime
View raw message