use of org.apache.lucene.sandbox.queries.FuzzyLikeThisQuery in project lucene-solr by apache.
the class KNearestFuzzyClassifier method knnSearch.
private TopDocs knnSearch(String text) throws IOException {
BooleanQuery.Builder bq = new BooleanQuery.Builder();
FuzzyLikeThisQuery fuzzyLikeThisQuery = new FuzzyLikeThisQuery(300, analyzer);
for (String fieldName : textFieldNames) {
// TODO: make this parameters configurable
fuzzyLikeThisQuery.addTerms(text, fieldName, 1f, 2);
}
bq.add(fuzzyLikeThisQuery, BooleanClause.Occur.MUST);
Query classFieldQuery = new WildcardQuery(new Term(classFieldName, "*"));
bq.add(new BooleanClause(classFieldQuery, BooleanClause.Occur.MUST));
if (query != null) {
bq.add(query, BooleanClause.Occur.MUST);
}
return indexSearcher.search(bq.build(), k);
}
use of org.apache.lucene.sandbox.queries.FuzzyLikeThisQuery in project lucene-solr by apache.
the class FuzzyLikeThisQueryBuilder method getQuery.
@Override
public Query getQuery(Element e) throws ParserException {
NodeList nl = e.getElementsByTagName("Field");
int maxNumTerms = DOMUtils.getAttribute(e, "maxNumTerms", DEFAULT_MAX_NUM_TERMS);
FuzzyLikeThisQuery fbq = new FuzzyLikeThisQuery(maxNumTerms, analyzer);
fbq.setIgnoreTF(DOMUtils.getAttribute(e, "ignoreTF", DEFAULT_IGNORE_TF));
final int nlLen = nl.getLength();
for (int i = 0; i < nlLen; i++) {
Element fieldElem = (Element) nl.item(i);
float minSimilarity = DOMUtils.getAttribute(fieldElem, "minSimilarity", DEFAULT_MIN_SIMILARITY);
int prefixLength = DOMUtils.getAttribute(fieldElem, "prefixLength", DEFAULT_PREFIX_LENGTH);
String fieldName = DOMUtils.getAttributeWithInheritance(fieldElem, "fieldName");
String value = DOMUtils.getText(fieldElem);
fbq.addTerms(value, fieldName, minSimilarity, prefixLength);
}
Query q = fbq;
float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
if (boost != 1f) {
q = new BoostQuery(fbq, boost);
}
return q;
}
Aggregations