Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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?
Comment | File | Size | Author |
---|---|---|---|
#8 | viewfield-expose_to_seach_api-1705874-8.patch | 3.89 KB | jerdavis |
#4 | viewfield-expose_to_seach_api-1705874-4.patch | 336 bytes | Ludo.R |
#5 | viewfield-expose_to_seach_api-1705874-5.patch | 2.3 KB | Ludo.R |
#6 | viewfield-expose_to_seach_api-1705874-6.patch | 3.66 KB | Ludo.R |
#7 | viewfield-expose_to_seach_api-1705874-7.patch | 3.69 KB | Ludo.R |
Comments
Comment #1
SilviuChingaru CreditAttribution: SilviuChingaru commentedhttps://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.
Comment #2
lquessenberry CreditAttribution: lquessenberry as a volunteer and commentedI 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.
Comment #3
Ludo.RI applied this patch and still don't see my field in Search API: https://www.drupal.org/project/viewfield/issues/477244#comment-12081410
Comment #4
Ludo.RHere'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.
Comment #5
Ludo.ROk, 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 oftext
- 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.
Comment #6
Ludo.RHere 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 textThis is done- This has to be tested/validated, as I don't know if this patch may break things regarding Entity API module
Comment #7
Ludo.RSmall typo fix.
Comment #8
jerdavisUpdating 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.