コード例 #1
0
  @SuppressWarnings("unchecked")
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public Response volumes(
      @QueryParam("categoryId") Long categoryId,
      @QueryParam("page") Integer page,
      @QueryParam("q") String q) {
    Volumes volumes = new Volumes();

    VolumeDAO volumeDAO = DAOFactory.getInstance().getVolumeDAO();
    FullTextSession fts = org.hibernate.search.Search.getFullTextSession(volumeDAO.getSession());

    try {
      Query query = buildLuceneQuery(categoryId, page, q);
      FullTextQuery createFullTextQuery =
          fts.createFullTextQuery(query, com.book.identification.model.Volume.class);
      addPaginationToQuery(createFullTextQuery, page);
      List<Volume> list = createFullTextQuery.list();
      for (Volume volume : list) {
        volume.setPage(page);
        volume.setQ(q);
      }
      volumes.setVolumes(createFullTextQuery.list());
    } catch (ParseException e1) {
      e1.printStackTrace();
    }

    if (volumes.getVolumes().isEmpty()) {
      return Response.ok("volumes : {}").build();
    }

    return Response.ok(volumes).build();
  }
コード例 #2
0
  private Query buildLuceneQuery(Long categoryId, Integer page, String q) throws ParseException {
    StringBuilder query = new StringBuilder();

    QueryParser queryParser =
        new org.apache.lucene.queryParser.QueryParser(
            Version.LUCENE_31, "title", new StandardAnalyzer((Version.LUCENE_31)));
    if (StringUtils.isNotBlank(q)) {
      query.append(buildQuery(q));
    }

    if (categoryId != null) {
      List<Long> childCategories =
          DAOFactory.getInstance().getCategoryDAO().childCategories(categoryId);
      if (StringUtils.isNotBlank(q)) {
        query.append("AND ( " + buildQuery(childCategories) + ")");
      } else {
        query.append(buildQuery(childCategories));
      }

      buildQuery(childCategories);
    }
    if (!StringUtils.isNotBlank(query)) {
      query.append("id:*");
    }
    queryParser.setAllowLeadingWildcard(true);
    return queryParser.parse(query.toString());
  }
コード例 #3
0
 @GET
 @Produces(MediaType.APPLICATION_JSON)
 @Path("reindex/")
 public Response reindex() {
   VolumeDAO volumeDAO = DAOFactory.getInstance().getVolumeDAO();
   FullTextSession fts = org.hibernate.search.Search.getFullTextSession(volumeDAO.getSession());
   try {
     fts.createIndexer().startAndWait();
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   return Response.ok("reindex").build();
 }
コード例 #4
0
 @GET
 @Produces(MediaType.APPLICATION_JSON)
 @Path("hash/")
 public Response hashing() throws IOException {
   VolumeDAO volumeDAO = DAOFactory.getInstance().getVolumeDAO();
   List<Volume> findAll = volumeDAO.findAll();
   Transaction beginTransaction = volumeDAO.getSession().beginTransaction();
   for (Volume volume : findAll) {
     String fileSHA1 = DigestUtils.shaHex(FileUtils.openInputStream(new File(volume.getPath())));
     volume.setHashSH1(fileSHA1);
   }
   beginTransaction.commit();
   return Response.ok("hashed").build();
 }