I am creating a Lucene Document like this:
Document document = new Document();
document.add(new Field(FIELD_FOLDER_PATH,mSearchInput, Field.Store.YES, Field.Index.NOT_ANALYZED ));
Reader reader = new FileReader(file);
document.add(new Field(FIELD_CONTENTS, reader));
indexWriter.addDocument(document);
When executing Query on CONTENTS and also using wild character * I am able to fetch results:
QueryParser queryParser = new QueryParser (Version.LUCENE_36,FIELD_CONTENTS, analyzer);
Query query = queryParser.parse(searchString+"*");
But when I am using the same Query for FIELD_FOLDER_PATH , I am getting no results:
QueryParser queryParser = new QueryParser (Version.LUCENE_36,FIELD_FOLDER_PATH, analyzer);
Query query = queryParser.parse(FolderPath+"*");
However only when I am providing the exact string , I am able to fetch the results.
My Question is : Why I am not able to use (*) to fetch results in FIELD_FOLDER_PATH? Is it because of the way I am creating the field?
You should use wildcard query to support this kind of feature. This link would help :
So what you should do exactly is create two queries one using queryparser and other using wildcard query , then use both the queries in a BooleanQuery with "SHOULD" clause for both the queries.
for details on boolean Query visit this link :
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.