Sorry, but you can only use a wildcard on a single term. "C0001.DevNm001"
gets indexed as two terms, "c0001" and "devnm001", so your wildcard won't
match any term (at least in this case.)
Also, if your query term includes a wildcard, it will not be fully analyzed.
Some filters such as lower case are defined as "multi-term", so they will be
performed, but the standard tokenizer is not being called, so the dot
remains and this whole term is treated as one term, unlike the index
analysis.
-- Jack Krupansky
-----Original Message-----
From: Milind
Sent: Tuesday, August 26, 2014 12:24 PM
To: java-user@lucene.apache.org
Subject: Why does this search fail?
I have a field with the value C0001.DevNm001. If I search for
C0001.DevNm001 --> Get Hit
DevNm00* --> Get Hit
C0001.DevNm00* --> Get No Hit
The field gets tokenized on the period since it's surrounded by a letter
and and a number. The query gets evaluated as a prefix query. I'd have
thought that this should have found the document. Any clues on why this
doesn't work?
The full code is below.
Directory theDirectory = new RAMDirectory();
Version theVersion = Version.LUCENE_47;
Analyzer theAnalyzer = new StandardAnalyzer(theVersion);
IndexWriterConfig theConfig =
new IndexWriterConfig(theVersion, theAnalyzer);
IndexWriter theWriter = new IndexWriter(theDirectory, theConfig);
String theFieldName = "Name";
String theFieldValue = "C0001.DevNm001";
Document theDocument = new Document();
theDocument.add(new TextField(theFieldName, theFieldValue,
Field.Store.YES));
theWriter.addDocument(theDocument);
theWriter.close();
String theQueryStr = theFieldName + ":C0001.DevNm00*";
Query theQuery =
new QueryParser(theVersion, theFieldName,
theAnalyzer).parse(theQueryStr);
System.out.println(theQuery.getClass() + ", " + theQuery);
IndexReader theIndexReader = DirectoryReader.open(theDirectory);
IndexSearcher theSearcher = new IndexSearcher(theIndexReader);
TopScoreDocCollector collector = TopScoreDocCollector.create(10,
true);
theSearcher.search(theQuery, collector);
ScoreDoc[] theHits = collector.topDocs().scoreDocs;
System.out.println("Hits found: " + theHits.length);
Output:
class org.apache.lucene.search.PrefixQuery, Name:c0001.devnm00*
Hits found: 0
--
Regards
Milind
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org