GSoC Week #3: Creating a views filter plugin for search_api_location_views module(First part)

If you remember in the previous post, I submitted tests for location data type, and location input plugin i.e raw input plugin. Although there are three location input plugins available i.e raw, geocoder and map. But as I discussed with my mentor and came across a solution that to release a working search_api_location module with only raw input plugin at the end of this month. Because geocoder module is not stable yet. So after fixing some issue of geocoder next month we will again start working for rest of the location input plugins.

As test passes for data type and raw input plugin, we had to concentrate on making a workable views filter plugin. This week, I was trying to play with search_API_Location_Views filter plugins. Before started hacking it, I learnt "How to make a views filter plugin"  from this great article. In our case the table which we are interested in is search_api_index_IndexID. IndexID is different for each index. we need to implement hook_views_data_alter() to define a filter of our own and to alter the  search_api_index_IndexID table.  

Remember  search_api_index_  is a virtual table. You can not find it in Drupal database. For each search index, There is a base table with key "search_api_index_INDEX", which contains field, filter, argument and sort handlers for all indexed fields. (Field handlers too, to allow things like click-sorting.)

Note, at first I could not see any location filter there in the views and getting some error related after I enabled search_api_location_views module. So for the time being I removed both geocoder and map plugins. And now location input plugins i.e Location(lat/long) and Location(lat/long Distance) are visible as shown in the below image. 

search api location

I verified all the written hooks and when tried to select location (Lat/Long) and save it I was getting schema error as given below:

InvalidArgumentException: The configuration property display.default.display_options.filters.field_location_lat_long_.value.distance doesn't exist. in Drupal\Core\Config\Schema\ArrayElement->get() (line 74 of core\lib\Drupal\Core\Config\Schema\ArrayElement.php).

I have investigated the error, and recently pushed a commit as a solution for the above schema issue. Now atleast I can able to save the raw plugin configuration. Next week I will be investigating if it is working properly or not and modify accordingly. Stay tuned for my next post.