首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用IndexTank获得结果?

如何使用IndexTank获得结果?
EN

Stack Overflow用户
提问于 2011-04-23 14:08:33
回答 1查看 271关注 0票数 1

我在Java客户端使用IndexTank,但似乎无法访问结果:

代码语言:javascript
复制
    SearchResults results = index.search(Query.forString(keywords));

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

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

有人知道我为什么会得到这个错误吗?谢谢。

EN

回答 1

Stack Overflow用户

发布于 2011-04-23 14:39:24

你所拥有的看起来很好。您确定要导入所有正确的类吗?这对我来说很有效:

代码语言:javascript
复制
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"));
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5762550

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档