Results 1 to 1 of 1
- 01-13-2011, 10:58 AM #1
Problem with search, when I rewriting index
I have simple code, It create index and rewrite data.
When I rewrite term I can't search anything. What could be the problem?Java 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; } }
I read documentation about NRT NearRealtimeSearch - Lucene-java Wiki. but this can't help.
Thanks.
Similar Threads
-
How to search russian texts in Lucene index?
By ArtUrlWWW in forum LuceneReplies: 0Last Post: 01-11-2011, 11:46 AM -
Pulling an Index made with Lucene to dev batch code for index listings
By txgeekgirl in forum LuceneReplies: 0Last Post: 10-29-2010, 08:15 PM -
Problems with javadoc Index search.
By heven in forum NetBeansReplies: 0Last Post: 08-09-2010, 10:46 AM -
problem with index file search
By rencin in forum LuceneReplies: 4Last Post: 08-17-2009, 10:27 AM -
url rewriting
By jithan in forum Java ServletReplies: 2Last Post: 06-23-2008, 06:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks