1

I already have a Suggest object filled with two suggestions. At this point I can't find any documentation or sample code to help guide me through fetching the suggestions from the Suggest object.

Below is how i'm fetching the Suggest Object

val generator:DirectCandidateGenerator = candidateGenerator("name")
            .prefixLength(0)
            .minWordLength(0)
            .suggestMode("always")
            .maxEdits(2);
val phraseSuggest:PhraseSuggestionBuilder = phraseSuggestion("did_you_mean")
        .field("name")
    .addCandidateGenerator(generator)
    .text(t)
    .gramSize(3);

val search = Global.getClient().prepareSearch("businesses")
  .setSearchType(SearchType.QUERY_THEN_FETCH)
  .setQuery(customQuery)
  .setFrom(0).setSize(max)
  .addSuggestion(phraseSuggest)
  .execute()
  .actionGet();


val suggest = search.getSuggest()
println("Suggest Size: " + suggest.size())

The above code is in Scala. It is pretty self explainatory if you understand Java. If you know the solution in Java then I can easily translate it into Scala code so no need to try and figure out Scala if you don't know it.

Any help would be greatly appreciated. Thank You

4
  • What's wrong? You get 0 suggestions I guess? Have you tried doing the same using REST? Commented Oct 18, 2013 at 8:49
  • No, like I said, the suggest object has two entities in it. The question is, How do I extract the suggestions? Commented Oct 18, 2013 at 14:36
  • The Suggest object is Iterable...not sure what I'm missing here... Commented Oct 18, 2013 at 14:42
  • Trying to forget what you wrote, moderation helps. Lets move on, by two entities you mean the two levels of iterable? Commented Oct 18, 2013 at 22:02

1 Answer 1

1

A rather ugly approach but works:

val options = suggest.iterator().next().iterator().next().getOptions()
options.asScala.map(x => x.getText.string).toList
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.