Example usage for org.apache.solr.client.solrj SolrQuery setTermsRegexFlag

List of usage examples for org.apache.solr.client.solrj SolrQuery setTermsRegexFlag

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj SolrQuery setTermsRegexFlag.

Prototype

public SolrQuery setTermsRegexFlag(String flag) 

Source Link

Usage

From source file:com.frank.search.solr.core.TermsQueryParser.java

License:Apache License

protected void appendTermsOptionsToSolrQuery(TermsOptions options, SolrQuery solrQuery) {
    solrQuery.setTerms(true);//  www .  ja  v  a 2  s. c  om
    if (options.getLimit() >= 0) {
        solrQuery.setTermsLimit(options.getLimit());
    }
    if (options.getMaxCount() >= -1) {
        solrQuery.setTermsMaxCount(options.getMaxCount());
    }
    if (options.getMinCount() >= 0) {
        solrQuery.setTermsMinCount(options.getMinCount());
    }
    if (StringUtils.hasText(options.getPrefix())) {
        solrQuery.setTermsPrefix(options.getPrefix());
    }
    if (StringUtils.hasText(options.getRegex())) {
        solrQuery.setTermsRegex(options.getRegex());
    }
    if (options.getRegexFlag() != null) {
        solrQuery.setTermsRegexFlag(options.getRegexFlag().toString().toLowerCase());
    }
    if (options.getSort() != null) {
        solrQuery.setTermsSortString(options.getSort().toString().toLowerCase());
    }
    if (options.getUpperBoundTerm() != null) {
        solrQuery.setTermsUpper(options.getUpperBoundTerm().getTerm());
        solrQuery.setTermsUpperInclusive(options.getUpperBoundTerm().isInclude());
    }
    if (options.getLowerBoundTerm() != null) {
        solrQuery.setTermsUpper(options.getLowerBoundTerm().getTerm());
        solrQuery.setTermsUpperInclusive(options.getLowerBoundTerm().isInclude());
    }
    if (!options.isRaw()) {
        solrQuery.setTermsRaw(options.isRaw());
    }

}

From source file:org.sleuthkit.autopsy.keywordsearch.TermComponentQuery.java

License:Open Source License

protected SolrQuery createQuery() {
    final SolrQuery q = new SolrQuery();
    q.setRequestHandler(TERMS_HANDLER);//from   ww  w. j a  v a  2s . co m
    q.setTerms(true);
    q.setTermsLimit(TERMS_UNLIMITED);
    q.setTermsRegexFlag("case_insensitive"); //NON-NLS
    //q.setTermsLimit(200);
    //q.setTermsRegexFlag(regexFlag);
    //q.setTermsRaw(true);
    q.setTermsRegex(queryEscaped);
    q.addTermsField(TERMS_SEARCH_FIELD);
    q.setTimeAllowed(TERMS_TIMEOUT);

    return q;

}

From source file:org.sleuthkit.autopsy.keywordsearch.TermsComponentQuery.java

License:Open Source License

/**
 * Executes the regex query as a two step operation. In the first step, the
 * Solr terms component is used to find any terms in the index that match
 * the regex. In the second step, term queries are executed for each matched
 * term to produce the set of keyword hits for the regex.
 *
 * @return A QueryResult object or null.
 *
 * @throws NoOpenCoreException/*  ww  w.java 2 s  .co  m*/
 */
@Override
public QueryResults performQuery() throws KeywordSearchModuleException, NoOpenCoreException {
    /*
     * Do a query using the Solr terms component to find any terms in the
     * index that match the regex.
     */
    final SolrQuery termsQuery = new SolrQuery();
    termsQuery.setRequestHandler(SEARCH_HANDLER);
    termsQuery.setTerms(true);
    termsQuery.setTermsRegexFlag(CASE_INSENSITIVE);
    termsQuery.setTermsRegex(searchTerm);
    termsQuery.addTermsField(SEARCH_FIELD);
    termsQuery.setTimeAllowed(TERMS_SEARCH_TIMEOUT);
    termsQuery.setShowDebugInfo(DEBUG_FLAG);
    termsQuery.setTermsLimit(MAX_TERMS_QUERY_RESULTS);
    List<Term> terms = KeywordSearch.getServer().queryTerms(termsQuery).getTerms(SEARCH_FIELD);
    /*
     * Do a term query for each term that matched the regex.
     */
    QueryResults results = new QueryResults(this, keywordList);
    for (Term term : terms) {
        /*
         * If searching for credit card account numbers, do a Luhn check on
         * the term and discard it if it does not pass.
         */
        if (keyword.getArtifactAttributeType() == ATTRIBUTE_TYPE.TSK_CARD_NUMBER) {
            Matcher matcher = CREDIT_CARD_NUM_PATTERN.matcher(term.getTerm());
            matcher.find();
            final String ccn = CharMatcher.anyOf(" -").removeFrom(matcher.group("ccn"));
            if (false == CREDIT_CARD_NUM_LUHN_CHECK.isValid(ccn)) {
                continue;
            }
        }

        /*
         * Do an ordinary query with the escaped term and convert the query
         * results into a single list of keyword hits without duplicates.
         *
         * Note that the filters field appears to be unused. There is an old
         * comment here, what does it mean? "Note: we can't set filter query
         * on terms query but setting filter query on fileResults query will
         * yield the same result." The filter is NOT being added to the term
         * query.
         */
        String escapedTerm = KeywordSearchUtil.escapeLuceneQuery(term.getTerm());
        LuceneQuery termQuery = new LuceneQuery(keywordList, new Keyword(escapedTerm, true));
        filters.forEach(termQuery::addFilter); // This appears to be unused
        QueryResults termQueryResult = termQuery.performQuery();
        Set<KeywordHit> termHits = new HashSet<>();
        for (Keyword word : termQueryResult.getKeywords()) {
            termHits.addAll(termQueryResult.getResults(word));
        }
        results.addResult(new Keyword(term.getTerm(), false), new ArrayList<>(termHits));
    }
    return results;
}