How to configure ElasticPress WordPress plugin to leverage exsting Elasticsearch index for autocomplete searchbox - wordpress

Facts:
Using existing Wordpress 4.8 implementation Added Elasticpress plugin
Have existing Elasticsearch 5.4 environment
Loaded 1,000 JSON documents from file, and successfully created an
index
Relevant fields in index: carName, carURI
Looking to create simple webpage in order to implement an autocomplete scenario, whereby user would begin searching for item by name (a car, let's say), searching against (carName) in the index, and gets a limited number of matching results for carName, with URI link to relevant webpage (carURI).
Upon reading documentation for ElasticPress, it appears primarily to index a Wordpress site, and commit it to ES as an index, and use it to search captured site data. Can it be leveraged as a search target from an existing index in ES?

Related

Search field - pre populate automatically with user location

I've seen some website, once you on the front page, it automatically populate the search field with your location. I want to implement the same thing for my directory site. One field, is for whatever they want to search for, and the second field is a location field for the user to enter the city or postcode they want to search on.
I want to pre-populate the location field, automatically once the user landed on front page. Any modules that I can use for this?
It will depend on which search engine/backend you use. Using Solr, you can use the Geolocation Field module in conjunction with Search API Location.
The Search API Location module adds the possibility of location based searching to the Search API module (currently only Apache Solr is supported as the service class).
Geolocation Field provides a field type to store geographical locations as pairs of latitude and longitude (lan,lng) as well as the necessary integration to display those locations through views, fields and using a number of different map providers.
Once configured, you will be able to pre-populate the location field by hooking into your search form using hook_form_alter.

Serialized data in Wordpress form is "serialized" again when saved in mysql

I have a challenge with the way data is stored from Wordpress into mysql.
I'm new to Wordpress - but I'm trying to combine different plugins to achieve a specific functionality on a website.
Plugin #1 uses a specific type of post and some metadata - the plugin works great.
Plugin #2 can create posts of custom types and with custom metadata from the frontend. A flexible and great plugin.
My intention is to use plugin #2 to create posts from the frontend for plugin #1, which requires that some specific metadata contains specific values (otherwise the data are interpretted wrong). These values are saved with hidden inputfields in a form.
My challenge is that a value (which is serialized) is kind of serialized again. The value is a:1:{i:0;s:3:"198";}
Plugin #2 handles it well (as the data is shown correct in front- and backend of the plugin) - BUT in myPhpAdmin I can see that the data is saved differently s:20:"a:1:{i:0;s:3:"198";}"; - and hence that value cannot be understood by plugin #1.
I'm thinking of two options:
change something so s:xx: isn't added to the value(-s)
make the frontend form/plugin save the data in a serialized way so the value gets the correct format.
Any recommendations? - can I in anyway achieve my functionality?
Looks like
s:20:"a:1:{i:0;s:3:"198";}";
value is being serialized twice. You can check the plugin source code to see why the plugin serializing same value twice and if can prevent it than both plugin can share same data.

WordPress REST API Global Search (API V2)

I am looking for a way to run a global search query across all or multiple post types using WP REST API.
I am able to search posts using:
http://example.com/wp-json/wp/v2/posts?search=test
In turn I am able to search pages using:
http://example.com/wp-json/wp/v2/pages?search=test
How do I search across both posts and pages? I was able to do this in WP REST API V1 by specifying multiple type[] variables in the query?
This might be a bit late but there is an endpoint for that in the v2-api: /wp-json/wp/v2/search.
You can search for any specific post_type by supplying it via subtype or leave it to the default (any) to search in all post_types.
Edit: Of course you can also specifiy multiple with an array as you did before.
Here are some examples using the REST API search endpoint for searching all content or specific content type(s).
Search For a Term in All Site Content
/wp-json/wp/v2/search/?search=searchterm
Search For a Term and Limit Results to a Custom Post Type
/wp-json/wp/v2/search/?subtype=book&search=searchterm
Search For a Term and Limit Results to multiple Custom Post Types
/wp-json/wp/v2/search/?subtype[]=book&subtype[]=movie&search=searchterm
REST API Search Result Documentation

Expose filter multiple search in drupal

I have one Drupal website where there is a list of all temples, mosques, church etc available. Now i want a search form in my front page where user can search temples, mosques, church etc. I am using View exposed filter for searching results. But problem is when i go to add filter criteria then It ask for specific CCK field to exposed.
In Drupal machine name is always unique. So for temples it takes different machine name and for mosques it takes different.
I want only one search form where user can search all temples, mosques etc. Right now i am using different search form for different one. How can i do this with only one search form???
One more thing I am using these modules for handling addresses and locations
Address Field - 7.x-1.0-beta3
Geofield - 7.x-1.1
GeoPHP - 7.x-1.6
Geocoder - 7.x-1.2
How can i search results based on city and locations?
Assuming that you want to make the searches by name, then you should use the same field for all the temples' names, regardless of their type. By doing that exposing that field will do what you want.

Drupal: map address geolocation search

I am using the gmap and location modules to display a map. I would like the users to be able to fill an address in a field and the map autocenters and autozooms to that address. Like maps.google.com does it.
Is there a module or any specific configuration I can do with drupal? Ultimately I would like to create an advance filter where user inputs country, province and address and posibly select from a drop down list. Something very similar to what it is done in the following link http://www.dei.gr/Default.aspx?id=30608&nt=18&lang=2&langid=1
Thanks.
The GMap Location Module is the one which fits the requirements most closely.
"Provides a map of all a site's nodes and a map of all of the site users."
If you'd like to create it by yourself:
Would suggest to create 2 tables - with labels and center-points - in order to populate these cascaded drop-downs.
The last input-box needs to geo-code the entered text - over the Google GeoCoder API.
Of course any centerpoint could be geo-coded - but you have a limit of 2.500 API requests per 24hrs on the PHP API,
unless being a premier customer (besides local results are just quicker). That's why it's recommend to store the center-points for each item in the drop-downs in a table - and only use the JS API (instead of the PHP API) for the last step.
The example which you provided reloads the whole page when changing the drop-downs, which should be avoided.

Resources