如何使用 IndexTank 获取结果?

发布于 2024-11-03 03:29:51 字数 335 浏览 0 评论 0原文

我将 IndexTank 与 Java 客户端一起使用,但我似乎无法访问结果:

    SearchResults results = index.search(Query.forString(keywords));

    for (Map<String, Object> document : results.results) {
        System.out.println("doc id: " + document.get("docid"));

最后一行失败并显示: 类型不匹配:无法从对象转换为字符串

有谁知道为什么我会收到此错误?谢谢。

I'm using IndexTank with the Java client, but I can't seem to access the results:

    SearchResults results = index.search(Query.forString(keywords));

    for (Map<String, Object> document : results.results) {
        System.out.println("doc id: " + document.get("docid"));

The last line fails with: Type mismatch: cannot convert from Object to String

Does anyone know why I get this error? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不奢求什么 2024-11-10 03:29:51

你所拥有的看起来不错。您确定导入了所有正确的类吗?这对我有用:

import java.util.HashMap;
import java.util.Map;

import com.flaptor.indextank.apiclient.Index;
import com.flaptor.indextank.apiclient.IndexTankClient;
import com.flaptor.indextank.apiclient.IndexTankClient.Query;
import com.flaptor.indextank.apiclient.IndexTankClient.SearchResults;

public class IndexTankExample {
    public static void main(String[] args) throws Exception {
        IndexTankClient client = new IndexTankClient("<PRIVATE URL>");
        Index index = client.getIndex("test");

        Map<String, String> fields = new HashMap<String, String>();
        fields.put("text", "foo bar baz");
        index.addDocument("1", fields);

        SearchResults results = index.search(Query.forString("bar"));
        for (Map<String, Object> document : results.results) {
            System.out.println("doc id: " + document.get("docid"));
        }
    }
}

What you have looks fine. Are you sure you're importing all of the right classes? This works for me:

import java.util.HashMap;
import java.util.Map;

import com.flaptor.indextank.apiclient.Index;
import com.flaptor.indextank.apiclient.IndexTankClient;
import com.flaptor.indextank.apiclient.IndexTankClient.Query;
import com.flaptor.indextank.apiclient.IndexTankClient.SearchResults;

public class IndexTankExample {
    public static void main(String[] args) throws Exception {
        IndexTankClient client = new IndexTankClient("<PRIVATE URL>");
        Index index = client.getIndex("test");

        Map<String, String> fields = new HashMap<String, String>();
        fields.put("text", "foo bar baz");
        index.addDocument("1", fields);

        SearchResults results = index.search(Query.forString("bar"));
        for (Map<String, Object> document : results.results) {
            System.out.println("doc id: " + document.get("docid"));
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文