dcsimg
Having problems with concurrency
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   madz_humour
Posted On:   Monday, April 17, 2006 09:51 PM

This codes were taken from a website,where i modified the directory, that is working fine but when considering the concurrency, this codes have problems 1.The codes for indexing public MakeIndex() throws Exception { // create a Lucene index IndexWriter instance: IndexWriter indexWriter ; try{ indexWriter= new IndexWriter("C:\eclipse-311\tryMadhan\MedicalRecordIndexRecords\index3", new StandardAnalyzer(), false); } catch(Exception e){ indexWriter=new IndexWriter("C:\eclipse-311\tryMadhan\MedicalRecordIndexRecords\index3", new StandardAnalyzer(), true); } File dir = new File(EXAMPLE_DOCUMENT_PATH); AllText   More>>

This codes were taken from a website,where i modified the directory, that is working fine but when considering the concurrency, this codes have problems



			1.The codes for indexing
			


public MakeIndex() throws Exception {
// create a Lucene index IndexWriter instance:

IndexWriter indexWriter ;
try{
indexWriter= new IndexWriter("C:\eclipse-311\tryMadhan\MedicalRecordIndexRecords\index3", new StandardAnalyzer(), false);
}
catch(Exception e){

indexWriter=new IndexWriter("C:\eclipse-311\tryMadhan\MedicalRecordIndexRecords\index3", new StandardAnalyzer(), true);
}
File dir = new File(EXAMPLE_DOCUMENT_PATH);
AllTextFilesFilter filter = new AllTextFilesFilter();
String[] ss = dir.list(filter);
if (ss == null || ss.length == 0) return;
for (int i = 0; i < ss.length; i++) {
String fullPath = EXAMPLE_DOCUMENT_PATH + "/" + ss[i];
// add the text in this file to the lucene index:
Document document = new Document();
// note: the second argument to Field.Text can be the string of text to index (in which
// case it is stored in the index) or a file reader (in which case the text is read
// and indexed, but not stored in the index)
document.add(Field.Text("text", new FileReader(fullPath)));
document.add(Field.UnIndexed("filepath", fullPath));
indexWriter.addDocument(document);
System.out.println("Wrote file " + fullPath + " to index.");
}
indexWriter.optimize();
indexWriter.close();
}

class AllTextFilesFilter implements FilenameFilter {
public AllTextFilesFilter() {
}
final public boolean accept(File dir, String name) {
if (name.equals(".DS_Store")) return false; // Mac OS X only - safe on other platforms
File ff = new File(dir.toString() + "/" + name);
if (ff.isDirectory()) return false;
return true;
}
}



2. The part for searching



			
Analyzer analyzer = new StandardAnalyzer();

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

System.out.print("Search query (enter a blank query to stop) : ");


while (true) {
System.out.print("Search query (enter a blank query to stop) : ");
String line = in.readLine();

if (line == null || line.length() < 1) break;

Query query = QueryParser.parse(line, "text", analyzer);
System.out.println("Searching for: " + query.toString("text"));
Searcher searcher = new IndexSearcher("C:\eclipse-311\tryMadhan\MedicalRecordIndexRecords\index3");
Hits hits = searcher.search(query);

System.out.println("Number of matching documents = " + hits.length());

for (int i = 0; i < hits.length(); i++) {
Document doc = hits.doc(i);
System.out.println("File: " + doc.get("filepath") + ", score: " + hits.score(i));
}
searcher.close();
}

}



problems are as follows



1.When i create 3 threads all indexing,there is a exception being thrown



3.When i create 4 threads with 2 indexing and 2 searching, the searching shows 0 where it suppose to show a correct result as 3 matching documents.



Hope to hear from any1 with a solution.I don't have the lucene in action book so i am unable to refer the book and i am also new to all this concurrency issue and lucene.Hope to hear a helping hand to solve my trouble.Thank You

   <<Less

Re: Having problems with concurrency

Posted By:   Otis_Gospodnetic  
Posted On:   Tuesday, April 18, 2006 07:43 PM

Read about IndexWriter in javadoc or Lucene in Action. You should have only 1 IndexWriter open per index.
About | Sitemap | Contact