Java 类org.hibernate.search.query.dsl.TermMatchingContext 实例源码

项目:u-qasar.platform    文件:ProjectSearchService.java   
@Override
   protected <P extends Project> TermMatchingContext setFullTextSearchFields(WildcardContext wc, Class<P> clazz) {
       if (Project.class.isAssignableFrom(clazz)) {
           return wc.onField("name").
                   andField("description").
                   andField("nodeKey").
                   andField("children.name").
                   andField("children.description").
                   andField("children.nodeKey").
                   andField("programmingLanguages_name").
                   andField("topics_name").
                   andField("customerTypes_name").
                   andField("projectTypes_name").
                   andField("softwareTypes_name").
                   andField("softwareLicenses_name").
                   andField("issueTrackingTools_name").
                   andField("sourceCodeManagementTools_name").
                   andField("staticAnalysisTools_name").
                   andField("testManagementTools_name").
                   andField("continuousIntegrationTools_name").
                   andField("softwareDevelopmentMethodologies_name");            
       } else {
           return super.setFullTextSearchFields(wc, clazz);
       }
}
项目:u-qasar.platform    文件:QMTreeNodeService.java   
@Override
protected <P extends QMTreeNode> TermMatchingContext setFullTextSearchFields(WildcardContext wc, Class<P> clazz) {
    if (QMTreeNode.class.isAssignableFrom(clazz)) {
        return wc.onField("name").
                andField("description").
                andField("nodeKey").
                andField("children.name").
                andField("children.description").
                andField("children.mKey");
    } else {
        return super.setFullTextSearchFields(wc, clazz);
    }
}
项目:u-qasar.platform    文件:TreeNodeService.java   
@Override
protected <P extends TreeNode> TermMatchingContext setFullTextSearchFields(WildcardContext wc, Class<P> clazz) {
    if (TreeNode.class.isAssignableFrom(clazz)) {
        return wc.onField("name").
                andField("description").
                andField("nodeKey").
                andField("children.name").
                andField("children.description").
                andField("children.nodeKey");

    } else {
        return super.setFullTextSearchFields(wc, clazz);
    }
}
项目:u-qasar.platform    文件:AbstractService.java   
private <P extends T> Collection<Long> fullTextSearchForIds(Class<P> clazz, String... terms) {
    FullTextEntityManager ftem = Search.getFullTextEntityManager(em);
    QueryBuilder qb = ftem.getSearchFactory().buildQueryBuilder().
            forEntity(clazz).get();
    Query luceneQuery;
    WildcardContext wc = qb.keyword().wildcard();
    TermMatchingContext tmc = setFullTextSearchFields(wc, clazz);
    Set<Long> results = new HashSet<>();
    try {
        for (String term : terms) {
            luceneQuery = tmc.ignoreAnalyzer().ignoreFieldBridge().
                    matching(term.toLowerCase()).createQuery();
            FullTextQuery query = ftem.
                    createFullTextQuery(luceneQuery, clazz);
            query.setProjection("id");
            List<Object[]> idList = query.getResultList();
            for (Object[] id : idList) {
                if (id[0] instanceof Long) {
                    results.add((Long) id[0]);
                }
            }
        }
    } catch (Exception e) {
        // because of lucene stop words
        logger.warn(e.getMessage(), e);
    }
    return results;
}
项目:spring-data-snowdrop    文件:LuceneQueryBuilder.java   
private TermMatchingContext keywordOnField(String fieldName) {
    return queryBuilder
        .keyword().onField(fieldName);
}
项目:u-qasar.platform    文件:AbstractService.java   
protected <P extends T> TermMatchingContext setFullTextSearchFields(WildcardContext wc, Class<P> clazz) {
    return wc.onField(AbstractEntity_.id.getName());
}
项目:u-qasar.platform    文件:ProductService.java   
@Override
protected <P extends Product> TermMatchingContext setFullTextSearchFields(WildcardContext wc, Class<P> clazz) {
    return wc.onField("name").andField("description");
}
项目:u-qasar.platform    文件:TeamService.java   
@Override
protected <P extends Team> TermMatchingContext setFullTextSearchFields(WildcardContext wc, Class<P> clazz) {
    return wc.onField("name");
}
项目:u-qasar.platform    文件:UserService.java   
@Override
protected <P extends User> TermMatchingContext setFullTextSearchFields(WildcardContext wc, Class<P> clazz) {
    return wc.onField("firstName").andField("lastName");
}
项目:u-qasar.platform    文件:ProcessService.java   
@Override
protected <P extends Process> TermMatchingContext setFullTextSearchFields(WildcardContext wc, Class<P> clazz) {
    return wc.onField("name").andField("description").andField("stages");
}
项目:jpasearch    文件:DefaultLuceneQueryBuilder.java   
@Override
public <T> Query build(FullTextEntityManager fullTextEntityManager, StringTermSelector<T> termSelector, Class<? extends T> type) {
    QueryBuilder builder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(type).get();

    BooleanJunction<?> context = builder.bool();
    boolean valid = false;
    if (termSelector.isNotEmpty()) {
        boolean hasTerms = false;
        BooleanJunction<?> termContext = builder.bool();
        for (String selected : termSelector.getSelected()) {
            if (isNotBlank(selected)) {
                String[] values = selected.split(PUNCTUATION);
                for (String value : values) {
                    if (isNotBlank(value) && (value.length() > 2)) {
                        List<String> fields = termSelector.getPaths();
                        BooleanJunction<?> valueContext = builder.bool();

                        addFuzzyMatch(builder, value, fields, termSelector.getSearchSimilarity(), valueContext);

                        addKeywordMatch(builder, value, fields, valueContext);

                        // wildcard search
                        // no #onFields on wildcardContext
                        WildcardContext wildcardContext = builder.keyword().wildcard();
                        TermMatchingContext termMatchingContext = null;
                        for (String field : fields) {
                            if (termMatchingContext != null) {
                                termMatchingContext = termMatchingContext.andField(field);
                            } else {
                                termMatchingContext = wildcardContext.onField(field);
                            }
                        }
                        valueContext.should(termMatchingContext. //
                                matching("*" + value + "*").createQuery());

                        if (termSelector.isOrMode()) {
                            termContext.should(valueContext.createQuery());
                        } else {
                            termContext.must(valueContext.createQuery());
                        }
                        hasTerms = true;
                    }
                }
            }
        }
        if (hasTerms) {
            context.must(termContext.createQuery());
            valid = true;
        }
    }
    return createQuery(builder, context, valid);
}