Building Custom Solr Query

Building Custom Solr Query

Solr search has great performance, is suitable even for use on large commercial websites and supports facets and multi-index searches. What if we want to build your own query or get all indexed nodes programmatically?

Yes, building the custom query for Solr content will solve the problem.

Benefits of custom Solr Query

  1. Reduces load time.
  2. Custom filters.

1. Initialize solr api query using your index name

// To get index field value
$public_index = “Name of your Index”
$index = search_api_index_load($public_index);
$query = new SearchApiQuery($index);

2. Building filter, you can add multiple filters in your query

// Build a filter.
$node_filter = $query->createFilter('AND');
$node_filter->condition('type', 'content_type', '=');
$node_filter->condition('status', NODE_PUBLISHED, '=');

3. Adding filters to query

// Added filter in query.
$filter->filter($node_filter);
$query->filter($filter);

4. Fetch results of custom query

// Fetch results.
$results = $query->execute()['results'];
$arr_nodes = array_keys(return $arr_node$results);
Hope this helped you to get most out of the system, feel free to share your reviews and Pick the best answer for your requirements.

Original Post: Building Custom Solr Query

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s