When using Views to display results from a Search API index the viewfields that exist on my indexed content do not show up as available fields to display. Would it be possible to make this happen, or could someone point me in the right direction to implement a solution?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

SilviuChingaru’s picture

https://drupal.org/node/477244#comment-7510777

This shuld fix this also. Give it a try and let me know if it works for you. If not I'll look into it.

lquessenberry’s picture

Issue summary: View changes

I too am having this issue. I tried the most recent version of the patch and I am still unable to see my viewfield as a field that I can use in Search API.

Ludo.R’s picture

I applied this patch and still don't see my field in Search API: https://www.drupal.org/project/viewfield/issues/477244#comment-12081410

Ludo.R’s picture

Status: Active » Needs work
FileSize
336 bytes

Here's a patch that allows the field to be exposed/known by Search API.
It however only indexes the view name (and possibly argument).

I don't know if the property_type should be changed to something else, or if more coding is needed.

I may wortk on this later on.

Ludo.R’s picture

Ok, I managed to go further.
The key is to expose the field to Entity API module (which is used by Search API).

Here's a first attempt, which works in my case. The view output is indexed by Search API and is searchable.

It still has to be improved:
- We probably need to provide a struct property type instead of text
- This has to be tested/validated, as I don't know if this patch may break things regarding Entity API module

This was mainly inspired by addressfield and date modules.

Ludo.R’s picture

Status: Needs work » Needs review
FileSize
3.66 KB

Here it is.

I've successfully indexed: vname, vargs and rendered properties.

To index the field in Search API, you need to add it through "Add related fields" in your search index.
Then you can select wether to index vname, vargs and rendered properties.

It still has to be improved:
- We probably need to provide a struct property type instead of text This is done
- This has to be tested/validated, as I don't know if this patch may break things regarding Entity API module

Ludo.R’s picture

Small typo fix.

jerdavis’s picture

Updating this patch. Added some conditional checks to prevent errors when a Viewfield was not populated. Also ensured that check_markup() was used for sanitization as we were getting escaped HTML returned from check_plain().

There are still issues with this. Views indexed with Pagers render with the pager, but the pager does not function correctly.

I'll consider submitting this to 7.x-3.x, but will not include it in 7.x-2.x

If there's still interest, please review the updated patch and provide feedback.