How to get results with IndexTank?

281 views Asked by At

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.

1

There are 1 answers

0
WhiteFang34 On

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"));
        }
    }
}