Today I'm trying to use the search API in Java SDK 1.7.0. When I try to use 
the snippet function, I cannot get it work correctly, here is my code:

IndexSpec indexSpec = IndexSpec.newBuilder().setName("test").setConsistency(
Consistency.PER_DOCUMENT).build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);

Document doc = Document.newBuilder().addField(Field.newBuilder().setName(
"title").setText("Google App Engine Search API"))
 .addField(Field.newBuilder().setName("content").setText("The Google App 
Engine Search API provides a simple model for indexing and searching data, 
and displaying the results."))
 .build();

index.add(doc);

QueryOptions options = QueryOptions.newBuilder().addExpressionToReturn(
FieldExpression.newBuilder().setName("snippet").setExpression("snippet(\"searching\",
 
content)").build())
 .setFieldsToReturn("title").build();
Query query = Query.newBuilder().setOptions(options).build(
"content:searching");

Results<ScoredDocument> results = index.search(query);

for (ScoredDocument _doc : results) {
 List<Field> fields = _doc.getExpressions();
 for (Field field : fields) {
 System.out.println(field.getName() + ":" + field.getText());
 }
 System.out.println(_doc.getField("title"));
 System.out.println(_doc.getField("content"));
 System.out.println(_doc.getField("snippet"));
}

output:
snippet:null
[Field(name=title, value=Google App Engine Search API, type=TEXT)]
null
null

I've also tried the following queryoptions and still cannot get the snippet:
QueryOptions.newBuilder().setFieldsToSnippet("content").
addExpressionToReturn(FieldExpression.newBuilder().setName("snippet").
setExpression("snippet(\"searching\", content)").build())
 .setFieldsToReturn("title").build();
QueryOptions.newBuilder().setFieldsToSnippet("content").setFieldsToReturn(
"title").build();
QueryOptions.newBuilder().setFieldsToSnippet("content").setFieldsToReturn(
"title", "content").build();
.. and many other

I've tried to run it on local machine with eclipse indigo SR2 (win7 x64) 
and deploy it to GAE and they show the same result.

Did I missed anything? Please help, thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/jIlghfPYREEJ.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to