小编Tom*_*Tom的帖子

如何在hibernate全文搜索中获得总计数?

我正在尝试通过以下链接使用hibernate全文: hibernate/search/4.1/reference/en-US/html/getting-started

基本上,它可以工作,但我想知道如何在执行全文查询时获得总计数,然后我可以告诉用户在这样的查询中将有多少结果和多少页面.

这是代码(使用JPA创建和执行搜索):

EntityManager em = entityManagerFactory.createEntityManager();
FullTextEntityManager fullTextEntityManager = 
org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
em.getTransaction().begin();

// create native Lucene query unsing the query DSL
// alternatively you can write the Lucene query using the Lucene query parser
// or the Lucene programmatic API. The Hibernate Search DSL is recommended though
QueryBuilder qb = fullTextEntityManager.getSearchFactory()
    .buildQueryBuilder().forEntity( Book.class ).get();
org.apache.lucene.search.Query query = qb
  .keyword()
  .onFields("title", "subtitle", "authors.name", "publicationDate")
  .matching("Java rocks!")
  .createQuery();

// wrap Lucene query in a javax.persistence.Query
javax.persistence.Query persistenceQuery = 
    fullTextEntityManager.createFullTextQuery(query, Book.class);
 persistenceQuery.setFirstResult((page …
Run Code Online (Sandbox Code Playgroud)

spring full-text-search hibernate hibernate-search

2
推荐指数
1
解决办法
4658
查看次数

使用Java将数据发布到网站时为什么会出现405错误?

我只是尝试使用以下代码将数据发布到谷歌,但总是有405错误,有人可以告诉我吗?

package com.tom.labs;
import java.net.*;
import java.io.*;
public class JavaHttp {
    public static void main(String[] args) throws Exception {
        File data = new File("D:\\in.txt");
        File result = new File("D:\\out.txt");
        FileOutputStream out = new FileOutputStream(result);
        OutputStreamWriter writer = new OutputStreamWriter(out); 
        Reader reader = new InputStreamReader(new FileInputStream(data));
        postData(reader,new URL("http://google.com"),writer);//Not working
        //postData(reader,new URL("http://google.com/search"),writer);//Not working
        sendGetRequest("http://google.com/search", "q=Hello");//Works properly
    }

    public static String sendGetRequest(String endpoint,
            String requestParameters) {
        String result = null;
        if (endpoint.startsWith("http://")) {
            // Send a GET request to the servlet
            try { …
Run Code Online (Sandbox Code Playgroud)

java http http-status-code-405

2
推荐指数
1
解决办法
6679
查看次数

web2py可以与svn一起使用吗?

我刚开始学习python和web2py.由于web2py的web界面开发,我想知道web2py如何与svn一起使用?如果团队想要建立一个网站,他们如何一起工作?如何控制源代码的迭代?

python web2py

1
推荐指数
1
解决办法
732
查看次数

我可以在 Java 中同时迭代两个数组吗?

对于一个数组,我可以这样迭代:

for(String str:myStringArray){

}
Run Code Online (Sandbox Code Playgroud)

如何同时迭代两个数组?因为我确信这两个的长度是相等的。我想要如下所示:

for(String attr,attrValue:attrs,attrsValue) {

}
Run Code Online (Sandbox Code Playgroud)

但这是错误的。

在这种情况下,也许映射是一个不错的选择,但是 3 个等长数组怎么样?我只是讨厌创建索引“int i”,它按以下格式使用:

for(int i=0;i<length;i++){
}
Run Code Online (Sandbox Code Playgroud)

java arrays

1
推荐指数
1
解决办法
5425
查看次数