1

如何从 Java 中的 IndexTank 搜索结果中获取文档“文本”?

我用包含内容的“文本”在 Clojure 中对文档进行了索引:

(. index addDocument (str id) {"text" name}))

以下是我在 Java 中执行查询的方式:

int start = 0;
int len = 4;
int function = 0;

// empty defaults
Map<Integer, Double> vars = Maps.newHashMap();
List<CategoryFilter> facetFilters = Lists.newArrayList();
List<RangeFilter> variableRangeFilters = Lists.newArrayList();
List<RangeFilter> functionRangeFilters = Lists.newArrayList();
Map<String, String> extras = Maps.newHashMap();  // Should default to all fields

SearchResults results = api.search(query, start, len, function, vars, 
              facetFilters, variableRangeFilters, functionRangeFilters, extras);

// Why is TEXT null? 
for (SearchResult result : results.getResults()) {
    System.out.println("DOCID: " + result.getDocId());        // this works
    System.out.println("TEXT: " +  result.getField("text"));  // this is null
}   

如您所见,我尝试了 result.getField("text") 但它返回一个空值。我在这里想念什么?

每次我尝试明确指定附加字段时...

Map<String, String> extras = Maps.newHashMap();
extras.put("fetch_fields", "text");

SearchResults results = api.search(q, start, len, function, vars, 
              facetFilters, variableRangeFilters, functionRangeFilters, extras);

...我得到一个 NullPointerException ...

com.flaptor.indextank.api.IndexEngineApiException: java.lang.NullPointerException
    at com.flaptor.indextank.api.IndexEngineApi.search(IndexEngineApi.java:90)
    at com.flaptor.indextank.api.resources.InstantLinks.run(InstantLinks.java:139)
    at com.ghosthack.turismo.servlet.Servlet.service(Servlet.java:55)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
    at org.eclipse.jetty.server.Server.handle(Server.java:346)
    at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)
    at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:1048)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:601)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:214)
    at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:535)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
    at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:106)
    at com.flaptor.indextank.index.storage.DocumentBinaryStorage.decompress(DocumentBinaryStorage.java:98)
    at com.flaptor.indextank.index.storage.DocumentBinaryStorage.getDocument(DocumentBinaryStorage.java:70)
    at com.flaptor.indextank.search.SnippetSearcher.search(SnippetSearcher.java:97)
    at com.flaptor.indextank.api.IndexEngineApi.search(IndexEngineApi.java:83)
    ... 22 more
4

0 回答 0