How to properly invoke search from another component

Viewed 30

Hi I am trying to execute a search from within a processing chain. Currently I am creating the Execution in the following way

Chain<Searcher> chain = Chain<>(new DomainSearcher())
Execution.Context context = Execution.Context.createContextStub()
Execution execution = new Execution(chain, context)
Query query = new Query()
query.model.queryTree.root = new WordItem(key, "field", true)
Result result = execution.search(query)

When I get the concreteHitCount of the result, it always shows 0, and when I get the yqlRepresentation, using the same yql query from outside the container will return the proper results. I'm assuming the issue arises from the context being an empty stub, but in all the documentation, any generated queries are from within a custom searcher which has access to the base execution such as the example found in the Blog Recommendation sample app. Any assistance on this would be greatly appreciated. Thank you.

1 Answers

Yes, the stub returned by Execution.Context.createContextStub() is just for testing and doesn't provide all the information that is needed. Instead:

  1. Get a com.yahoo.search.searchchain.ExecutionFactory injected in your component (by declaring it as a parameter in the constructor).

  2. To get an execution, call executionFactory.newExecution(chain)

Related