lucene-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doron Cohen <cdor...@gmail.com>
Subject Re: Problem with search, when I rewriting index
Date Tue, 18 Jan 2011 06:49:52 GMT
Hi,
Nothing is found because the index reader is created prior to adding the
docs.
Once an index reader is created it will always "see" the same state
(snapshot) of the index and will not be "aware" of further changes.
When using NRT API as above (obtaining IndexReader from IndexWriter) it is
sufficient to obtain it just after adding the docs.
Otherwise, when opening the index reader over the directory, also commit()
is required.
Hope this helps, javadocs in these classes should help as well.
Doron.

On Fri, Jan 14, 2011 at 12:16 PM, Pitbull <trackstudio2010@gmail.com> wrote:

>
> 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message