1

Java クライアントで IndexTank を使用していますが、結果にアクセスできないようです。

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

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

最後の行は次のエラーで失敗します: タイプの不一致: オブジェクトから文字列に変換できません

このエラーが発生する理由を知っている人はいますか? ありがとう。

4

1 に答える 1

1

あなたが持っているものはうまく見えます。正しいクラスをすべてインポートしていますか? これは私のために働く:

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"));
        }
    }
}
于 2011-04-23T06:39:24.103 に答える