package lucene;

import java.io.IOException;
import java.io.StringReader;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.Version;

import util.Variables;


public class QueryParser {
	private static QueryParser INSTANCE = null;
	private QueryParser() {}
	public static QueryParser getInstance() {
		if ( INSTANCE == null ) INSTANCE = new QueryParser();
		return INSTANCE;
	}
	
	public Query parseAsField(String qText, String field) throws IOException {
		Analyzer analyzer = new SmartChineseAnalyzer(Version.LUCENE_46);
		TokenStream stream = analyzer.tokenStream(null, new StringReader(qText));
		CharTermAttribute cattr = stream.addAttribute(CharTermAttribute.class);
		stream.reset();
		PhraseQuery query = new PhraseQuery();
		while ( stream.incrementToken() ) {
			query.add(new Term(field, cattr.toString()));
			System.out.println(cattr.toString());
		}
		query.setSlop(Integer.parseInt(Variables.getInstance().getProperties().getProperty("phraseSlop")));
		stream.end();
		stream.close();
		analyzer.close();
		return query;
	}
}


@@ -68,16 +68,100 @@
 eader;%0A%0A
+import org.apache.logging.log4j.LogManager;%0Aimport org.apache.logging.log4j.Logger;%0A
 import o
@@ -188,32 +188,32 @@
 lysis.Analyzer;%0A
-
 import org.apach
@@ -590,16 +590,99 @@
 arser %7B%0A
+%09private static Logger logger = LogManager.getLogger(QueryParser.class.getName());%0A
 %09private
@@ -943,16 +943,46 @@
 ption %7B%0A
+%09%09logger.entry(qText, field);%0A
 %09%09Analyz
@@ -1517,16 +1517,16 @@
 lose();%0A
-
 %09%09analyz
@@ -1533,24 +1533,46 @@
 er.close();%0A
+%09%09logger.exit(query);%0A
 %09%09return que

Add logger to QueryParser