I am currently using an extension method to index extra properties in the index for the website I am working on. I have verified that this is being indexed correctly in the index.
I am wondering how I would filter against this and return it to an API. Currently, the only suggestion I have seen is to call the extension method again to get the information needed, but ideally, I would like to return this from the index rather than calling the logic to get the required information again.
Is there any way to get this information from the index again rather than calling the same method to work out the information?
Using an extension method is the way to go. The method will not be called, instead it's translated into a filter that will be executed on the index. E.g.:
var query = this.client.UnfiedSearchFor("bananas")
.Filter(x => x.MyExtensionMethod().Match("Monkey"))
In this case the logic in MyExtensionMethod will not be executed.
Just to clarify even further... What you pass in the filter is an expression and not a function that will be invoked. The expression is then translated into filters that Find/Elastic understands.
Is there a way to access the values after the find query has returned a list of the results. For example, if I have a URL indexed as an extra property, is there a way to access that and return it in an API call after the find query has returned the results?
Thanks for your example!
What type of objects are you indexing? Why not add the URL as a property on that object then?
If you're searching for Episerver content, there is no nice way to get the value from the index since Find will only retrieve the ContentReference and then get the actual data from Episerver's IContentLoader, so then you have to call your extension method again.
If you're using UnfiedSearch there is already a metadata dictionary on UnifiedSearchHit where you can add custom data and also filter on.