lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Xu Chu <1989ch...@gmail.com>
Subject SpanTermQuery Issue
Date Fri, 03 Oct 2014 02:52:19 GMT
Hi everyone

In the following piece of code, Query test1 returns result, while Query test2 does not return
result!! Obviously “Toronto” is appearing in the doc. 
Can any one tell me what’s wrong? 

Thanks



private static void testRAMSpam() throws IOException
	{
		 RAMDirectory directory = new RAMDirectory();
		 Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_4_10_0);
	     IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_4_10_0, analyzer);

		 IndexWriter writer = new IndexWriter(directory,  iwc);
		 Document doc = new Document();
		 doc.add(new TextField("f",
		    "Project X took place in Waterloo. It was successful", Field.Store.YES));
		 writer.addDocument(doc);
		 
		 
		  doc = new Document();
		 doc.add(new TextField("f",
		"Project Y took place in Toronto. It was also good.", Field.Store.YES));
		 writer.addDocument(doc);
		 writer.close();
		 
		 IndexReader   reader = IndexReader.open(directory);
		 IndexSearcher   searcher = new IndexSearcher(reader);
		 
		 SpanTermQuery test1 = new SpanTermQuery(new Term("f", "good"));
		 System.out.println("test span query: " + test1.toString());
		 TopDocs results1  = searcher.search(test1, 100);
		 System.out.println("num result 1 : " + results1.totalHits);
		 
		 
		 SpanTermQuery test2 = new SpanTermQuery(new Term("f", "Toronto"));
		 System.out.println("test span query: " + test2.toString());
		 TopDocs results2  = searcher.search(test2, 100);
		 System.out.println("num result 2: " + results2.totalHits);
	}
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message