Example usage for org.apache.lucene.search Sort RELEVANCE

List of usage examples for org.apache.lucene.search Sort RELEVANCE

Introduction

In this page you can find the example usage for org.apache.lucene.search Sort RELEVANCE.

Prototype

Sort RELEVANCE

To view the source code for org.apache.lucene.search Sort RELEVANCE.

Click Source Link

Document

Represents sorting by computed relevance.

Usage

From source file:net.jforum.core.hibernate.SearchDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public SearchResult search(SearchParams params) throws ParseException {
    String buildQuery = params.buildQuery();
    FullTextQuery query = this.createQuery(buildQuery);

    query.setFirstResult(params.getStart());
    query.setMaxResults(params.getMaxResults());
    query.setFetchSize(params.getMaxResults());

    if (params.getSort() == SearchSort.DATE) {
        query.setSort(new Sort(new SortField("date", params.getSortType() == SearchSortType.DESC)));
    } else if (params.getSort() == SearchSort.RELEVANCE) {
        query.setSort(Sort.RELEVANCE);
    }/* www.j av a2 s.c  om*/

    return new SearchResult(query.list(), query.getResultSize());
}

From source file:net.mojodna.searchable.AbstractSearcher.java

License:Apache License

/**
 * Search the index with the specified query.
 * //  w  w w .j  a v  a 2  s  .  co m
 * @param query Query to use.
 * @param filter Filter to use.
 * @param offset Offset to begin result set at.
 * @param count Number of results to return.
 * @return ResultSet containing results.
 * @throws IndexException
 */
protected ResultSet doSearch(final Query query, final Filter filter, final Integer offset, final Integer count)
        throws IndexException {
    return doSearch(query, filter, offset, count, Sort.RELEVANCE);
}

From source file:net.mojodna.searchable.AbstractSearcher.java

License:Apache License

/**
 * Search the index with the specified query.
 * /*from   w  ww. jav  a 2 s.  c  om*/
 * @param query Query to use.
 * @param filter Filter to use.
 * @param offset Offset to begin result set at.
 * @param count Number of results to return.
 * @param sortField Field to sort by.
 * @return ResultSet containing results.
 * @throws IndexException
 */
// TODO add support for String[] sortFields
protected ResultSet doSearch(final Query query, final Filter filter, final Integer offset, final Integer count,
        final String sortField) throws IndexException {
    Sort sort = Sort.RELEVANCE;
    if (StringUtils.isNotBlank(sortField))
        sort = new Sort(IndexSupport.SORTABLE_PREFIX + sortField);
    return doSearch(query, filter, offset, count, sort);
}

From source file:net.mojodna.searchable.AbstractSearcher.java

License:Apache License

/**
 * Search the index with the specified query.
 * //ww w .j a  va  2s  .c  o  m
 * @param query Query to use.
 * @param filter Filter to use.
 * @param offset Offset to begin result set at.
 * @param count Number of results to return.
 * @param sortField Field to sort by.
 * @param reverse Whether to reverse the resultset. 
 * @return ResultSet containing results.
 * @throws IndexException
 */
protected ResultSet doSearch(final Query query, final Filter filter, final Integer offset, final Integer count,
        final String sortField, final boolean reverse) throws IndexException {
    Sort sort = Sort.RELEVANCE;
    if (StringUtils.isNotBlank(sortField))
        sort = new Sort(IndexSupport.SORTABLE_PREFIX + sortField, reverse);

    return doSearch(query, filter, offset, count, sort);
}

From source file:net.mojodna.searchable.AbstractSearcher.java

License:Apache License

/**
 * Search the index with the specified query.
 * //from ww  w.  j  a  v a  2  s .  c om
 * @param query Query to use.
 * @param offset Offset to begin result set at.
 * @param count Number of results to return.
 * @return ResultSet containing results.
 * @throws IndexException
 */
protected ResultSet doSearch(final Query query, final Integer offset, final Integer count)
        throws IndexException {
    return doSearch(query, offset, count, Sort.RELEVANCE);
}

From source file:net.mojodna.searchable.AbstractSearcher.java

License:Apache License

/**
 * Search the index with the specified query.
 * //  w  w w  . j  a v a 2  s  .  com
 * @param query Query to use.
 * @param offset Offset to begin result set at.
 * @param count Number of results to return.
 * @param sortField Field to sort by.
 * @return ResultSet containing results.
 * @throws IndexException
 */
// TODO add support for String[] sortFields
protected ResultSet doSearch(final Query query, final Integer offset, final Integer count,
        final String sortField) throws IndexException {
    Sort sort = Sort.RELEVANCE;
    if (StringUtils.isNotBlank(sortField))
        sort = new Sort(IndexSupport.SORTABLE_PREFIX + sortField);
    return doSearch(query, offset, count, sort);
}

From source file:net.mojodna.searchable.AbstractSearcher.java

License:Apache License

/**
 * Search the index with the specified query.
 * //from w  w w.j a v  a 2  s .c o m
 * @param query Query to use.
 * @param offset Offset to begin result set at.
 * @param count Number of results to return.
 * @param sortField Field to sort by.
 * @param reverse Whether to reverse the resultset. 
 * @return ResultSet containing results.
 * @throws IndexException
 */
protected ResultSet doSearch(final Query query, final Integer offset, final Integer count,
        final String sortField, final boolean reverse) throws IndexException {
    Sort sort = Sort.RELEVANCE;
    if (StringUtils.isNotBlank(sortField))
        sort = new Sort(IndexSupport.SORTABLE_PREFIX + sortField, reverse);

    return doSearch(query, offset, count, sort);
}

From source file:net.mojodna.searchable.AbstractSearcher.java

License:Apache License

/**
 * Search the index with the specified query.
 * //from  w ww  . jav  a2 s .c o  m
 * @param query Query to use.
 * @param clazz Type of object being searched for.
 * @param offset Offset to begin result set at.
 * @param count Number of results to return.
 * @return ResultSet containing results.
 * @throws IndexException
 */
protected ResultSet doSearch(final String query, final Class<? extends Searchable> clazz, final Integer offset,
        final Integer count) throws IndexException {
    return doSearch(query, clazz, offset, count, Sort.RELEVANCE);
}

From source file:net.mojodna.searchable.AbstractSearcher.java

License:Apache License

/**
 * Search the index with the specified query.
 * /*from  w  w  w  .j a  v  a 2  s . c  o m*/
 * @param query Query to use.
 * @param filter Filter to use.
 * @param clazz Type of object being searched for.
 * @param offset Offset to begin result set at.
 * @param count Number of results to return.
 * @return ResultSet containing results.
 * @throws IndexException
 */
protected ResultSet doSearch(final String query, final Filter filter, final Class<? extends Searchable> clazz,
        final Integer offset, final Integer count) throws IndexException {
    return doSearch(query, filter, clazz, offset, count, Sort.RELEVANCE);
}

From source file:net.mojodna.searchable.AbstractSearcher.java

License:Apache License

/**
 * Search the index with the specified query.
 * //from   w w  w  . j av  a  2 s.  c o m
 * @param query Query to use.
 * @param filter Filter to use.
 * @param offset Offset to begin result set at.
 * @param count Number of results to return.
 * @return ResultSet containing results.
 * @throws IndexException
 */
protected ResultSet doSearch(final String query, final Filter filter, final Integer offset, final Integer count)
        throws IndexException {
    return doSearch(query, filter, offset, count, Sort.RELEVANCE);
}