⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queryparsermodificado.java

📁 Calculate TFIDF using MySQL and Lucene on Cystic Fibrosis
💻 JAVA
字号:
package br.ufrj.cos.bri.model;

import java.util.StringTokenizer;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.Query;

public class QueryParserModificado extends QueryParser {

	public QueryParserModificado(String f, Analyzer a) {
		super(f, a);
	}
	
	public Query getPhQuery(IndexReader reader, String field, String pergunta, int phraseSlop) {
		PhraseQuery pq = this.newPhraseQuery();
		StringTokenizer tk = new StringTokenizer(pergunta, " ");
		while (tk.hasMoreElements()) {
			pq.add(new Term(field, tk.nextToken()));
		}
		pq.setSlop(phraseSlop);
		return pq;
	}
	
	public Query getFuzzy(String field, String termStr, float minSimilarity) {
		try {
			return this.getFuzzyQuery(field, termStr, minSimilarity);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -