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

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

Introduction

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

Prototype

public SolrQuery() 

Source Link

Usage

From source file:de.fatalix.bookery.bl.solr.SolrHandler.java

License:Open Source License

public List<BookEntry> getBookDetail(String bookID) throws SolrServerException {
    SolrServer solr = null;/*from   ww  w .j a  v a2s .c om*/
    try {
        solr = bookeryService.getSolrConnection();
    } catch (IOException ex) {
        throw new SolrServerException(ex.getMessage());
    }
    SolrQuery query = new SolrQuery();
    query.setQuery("id:" + bookID);
    query.setRows(1);
    query.setFields(
            "id,author,title,isbn,publisher,description,language,releaseDate,likes,downloadcount,uploader,viewed,shared,cover,thumbnail,thumbnailgenerated,likedby");
    QueryResponse rsp = solr.query(query);
    return rsp.getBeans(BookEntry.class);
}

From source file:de.fatalix.bookery.bl.solr.SolrHandler.java

License:Open Source License

public List<BookEntry> getEpubBook(String bookID) throws SolrServerException {
    SolrServer solr = null;/*w  ww . java 2s  .  c o  m*/
    try {
        solr = bookeryService.getSolrConnection();
    } catch (IOException ex) {
        throw new SolrServerException(ex.getMessage());
    }
    SolrQuery query = new SolrQuery();
    query.setQuery("id:" + bookID);
    query.setRows(1);
    query.setFields("id,epub");
    QueryResponse rsp = solr.query(query);
    return rsp.getBeans(BookEntry.class);
}

From source file:de.fatalix.bookery.bl.solr.SolrHandler.java

License:Open Source License

public List<BookEntry> getMobiFormat(String bookID) throws SolrServerException {
    SolrServer solr = null;//from   w ww .  j av a  2  s  .  c om
    try {
        solr = bookeryService.getSolrConnection();
    } catch (IOException ex) {
        throw new SolrServerException(ex.getMessage());
    }
    SolrQuery query = new SolrQuery();
    query.setQuery("id:" + bookID);
    query.setRows(1);
    query.setFields("id,mobi");
    QueryResponse rsp = solr.query(query);
    return rsp.getBeans(BookEntry.class);
}

From source file:de.fatalix.bookery.bl.solr.SolrHandler.java

License:Open Source License

public long checkSolr() throws SolrServerException, IOException {
    SolrServer solr = bookeryService.getSolrConnection();
    SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    query.setRows(1);/*  w ww  .  j  av  a2  s  .c  o  m*/
    QueryResponse rsp = solr.query(query);

    return rsp.getResults().getNumFound();
}

From source file:de.fatalix.bookery.bl.WatchListService.java

License:Open Source License

public List<BookEntry> getAllBooks(List<WatchList> watchList) throws SolrServerException {
    if (watchList.isEmpty()) {
        return Collections.EMPTY_LIST;
    }//from ww  w .j a  v a 2 s  . c  o m
    String searchString = "id:(";
    for (WatchList watchListItem : watchList) {
        searchString = searchString + "\"" + watchListItem.getBookId() + "\",";
    }
    searchString = searchString.substring(0, searchString.length() - 1) + ")";

    SolrQuery query = new SolrQuery();
    query.setRows(20);
    query.setStart(0);
    query.setQuery(searchString);
    query.setSort(SolrQuery.SortClause.asc("author"));
    query.setFields(SolrSearchUtil.DEFAULT_FIELDS);

    return bookService.searchBooks(query).getBeans(BookEntry.class);

}

From source file:de.fatalix.bookery.bl.WatchListService.java

License:Open Source License

public SolrQuery getSolrQuery(List<WatchList> watchList) {
    if (watchList.isEmpty()) {
        return null;
    }//from  w ww  .  j  av  a 2  s . c  om
    String searchString = "id:(";
    for (WatchList watchListItem : watchList) {
        searchString = searchString + "\"" + watchListItem.getBookId() + "\",";
    }
    searchString = searchString.substring(0, searchString.length() - 1) + ")";

    SolrQuery query = new SolrQuery();
    query.setRows(20);
    query.setStart(0);
    query.setQuery(searchString);
    query.setSort(SolrQuery.SortClause.asc("author"));
    query.setFields(SolrSearchUtil.DEFAULT_FIELDS);
    return query;
}

From source file:de.fatalix.bookery.view.home.HomeView.java

License:Open Source License

@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
    try {//from   w  w w  .ja va  2 s .  c o  m
        bookCount.setValue("Aktuell sind " + presenter.getBookCount() + " Bcher in der Bookery");

        String searchString = SolrSearchUtil.generateSearchString("");

        SolrQuery query = new SolrQuery();
        query.setRows(6);
        query.setStart(0);
        query.setQuery(searchString);
        query.setSort(SolrQuery.SortClause.desc("likes"));
        query.setFields(SolrSearchUtil.DEFAULT_FIELDS);

        QueryResponse response = presenter.searchBooks(query);
        mostLikedLane.loadLane("Beliebteste Bcher", response.getBeans(BookEntry.class),
                SearchView.id + "/likes");

        query.setSort(SolrQuery.SortClause.desc("downloadcount"));
        response = presenter.searchBooks(query);
        mostLoadedLane.loadLane("Meist geladene Bcher", response.getBeans(BookEntry.class),
                SearchView.id + "/downloads");

        searchString = SolrSearchUtil
                .addNewBooksSearchString(SecurityUtils.getSubject().getPrincipal().toString(), searchString);
        query.setQuery(searchString);
        query.setSort(SolrQuery.SortClause.asc("author"));
        response = presenter.searchBooks(query);
        newBooksLane.loadLane("Neue Bcher", response.getBeans(BookEntry.class),
                SearchView.id + "/auhtor/true");

        query = presenter.getWatchListQuery(SecurityUtils.getSubject().getPrincipal().toString());
        if (query != null) {
            query.setRows(6);
            response = presenter.searchBooks(query);
            watchListLane.loadLane("Deine Merkliste", response.getBeans(BookEntry.class), WatchListView.id);
        } else {
            watchListLane.loadLane("Deine Merkliste", Collections.EMPTY_LIST, WatchListView.id);
        }

    } catch (SolrServerException ex) {
        logger.error(ex, ex);
    }
}

From source file:de.fatalix.bookery.view.search.SearchView.java

License:Open Source License

@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
    SolrQuery.SortClause sortClause = SolrQuery.SortClause.asc("author");

    String searchString = SolrSearchUtil.generateSearchString(appHeader.getSearchText());

    String[] params = event.getParameters().split("/");
    if (params.length > 0) {
        String sortParameter = params[0];
        switch (sortParameter) {
        case "author":
            sortClause = SolrQuery.SortClause.asc("author");
            break;
        case "likes":
            sortClause = SolrQuery.SortClause.desc("likes");
            break;
        case "downloads":
            sortClause = SolrQuery.SortClause.desc("downloadcount");
            break;
        }/* ww w .j av a2 s.  c  o m*/

        if (params.length > 1) {
            String viewer = SecurityUtils.getSubject().getPrincipal().toString();
            searchString = SolrSearchUtil.addNewBooksSearchString(viewer, searchString);
        }
    }
    SolrQuery query = new SolrQuery();
    query.setRows(20);
    query.setStart(0);
    query.setQuery(searchString);
    query.setSort(sortClause);
    query.setFields(SolrSearchUtil.DEFAULT_FIELDS);
    searchLayout.searchBooks(query, true);
}

From source file:de.hebis.it.hds.gnd.out.AutorityRecordSolrFinder.java

License:Open Source License

/**
 * Do real time get.// w w  w.ja v  a  2 s.  c  o  m
 *
 * @param documentId the id of the authority record
 * @return a authority bean representing the authority record or null if the id does not exist.
 * @throws AuthorityRecordException
 */
private AuthorityBean doRealTimeGet(String documentId) throws AuthorityRecordException {
    QueryResponse response = null;
    SolrQuery rtg_query = new SolrQuery();
    rtg_query.setRequestHandler("/get");
    rtg_query.set("fl", "fullrecord");
    rtg_query.setFields("id", "preferred", "synonyms");
    rtg_query.set("id", documentId);
    try {
        response = server.query(rtg_query);
        if (response.getStatus() != 0)
            throw new SolrServerException("Response state: " + response.getStatus());
    } catch (SolrServerException | IOException e) {
        e.printStackTrace();
        throw new AuthorityRecordException("Solr query \"" + rtg_query.toString() + "\" can't be executed.", e);
    }
    // Workaround: RTG does not allow to call response.getBeans(AuthorityBean.class);
    NamedList<Object> result = response.getResponse();
    if (result == null)
        throw new AuthorityRecordException("Solr query \"" + rtg_query.toString() + "\" has no result.");
    SolrDocument doc = (SolrDocument) result.get("doc");
    if ((doc == null) || (doc.size() == 0)) {
        if (LOG.isDebugEnabled())
            LOG.debug("Solr query \"" + rtg_query.toString() + "\" No doc found.");
        return null;
    }
    return documentObjectBinder.getBean(AuthorityBean.class, doc);
}

From source file:de.kp.ames.web.core.search.SearcherImpl.java

License:Open Source License

public String facet() throws Exception {

    /*/* www  . ja  v a 2  s  .  c  o m*/
     * Create query
     */
    SolrQuery query = new SolrQuery();
    query.setRows(0);

    /*
     * A single facet field is supported
     */
    query.addFacetField(JsonConstants.J_FACET);
    query.setQuery("*");

    /*
     * Retrieve facets from Apache Solr
     */
    QueryResponse response = solrProxy.executeQuery(query);
    FacetField facet = response.getFacetField(JsonConstants.J_FACET);

    /*
     * Evaluate response
     */
    if (facet == null)
        return new JSONArray().toString();

    /*
     * Sort search result
     */
    StringCollector collector = new StringCollector();

    List<Count> values = facet.getValues();
    if (values == null)
        return new JSONArray().toString();

    for (int i = 0; i < values.size(); i++) {

        Count count = values.get(i);
        String name = facet.getName();

        JSONObject jCount = new JSONObject();

        jCount.put(JsonConstants.J_COUNT, count.getCount());

        jCount.put(JsonConstants.J_FIELD, facet.getName());
        jCount.put(JsonConstants.J_VALUE, count.getName());

        collector.put(name, jCount);

    }

    JSONArray jArray = new JSONArray(collector.values());
    return jArray.toString();

}