Faceted Search (solr) vs Good old filtering via PHP?

Asked
Active3 hr before
Viewed126 times

6 Answers

search
90%

To do faceted search in MySQL requires you to join tables, while Solr indexes the document facets automatically for filtering. You can generally achieve fast response times using Solr (<100ms for a multi-facet search query) on average hardware. While MySQL will take longer for the same search, it can be optimized with indexes to achieve similar response times.,You can created faceted search with just PHP and MySQL, Drupal Faceted Search is a good example. But if you already use Solr, you get faceted search included for free.,They are the same thing, but Magento and al uses different wording, probably to be catchy. As far as I know, Magento supports both the Solr faceted search or the MySQL one. The main difference is the performance. , 1 @RPM: Not entirely sure what you mean. You may want to open a question and link to this one, it'll be easier to explain for you and easier to answer for me and other users. It's a little hard to explain complicated SQL queries in comments. ;-) – netcoder Jun 29 '12 at 14:46

product

+ -- -- + -- -- -- -- -- -- +
|
id | name |
   + -- -- + -- -- -- -- -- -- +
   |
   1 | blue paint |
   |
   2 | red paint |
   + -- -- + -- -- -- -- -- -- +
load more v
88%

Featuring a video from Acro Media’s YouTube tutorial series Tech Talk, this article will walk you through setting up an awesome Drupal Commerce product catalogue using Search API and Solr, and then adding various ways of filtering the results (product search, sorting options and Facet categories)., Things you need: a running Solr server, Drupal 8 (or higher) with Commerce, Search API. Solr and Facets modules installed. ,Data source should be ‘Product’This can be anything, but we’re creating a Commerce catalogue and so we want to use the store products.,Now we’ll start setting up a Fulltext search field to let our users filter results using a product search field. The first thing we need to do is add some datasource fields to our index that the search will use.

load more v
72%

Drop-in support for WP_Query with the “solr-integrate” parameter set to true.,Indexing and faceting on custom fields.,Completely replaces default WordPress search, just install and configure.,Completely integrated into default WordPress theme and search widget.

All Solr Power related commands are grouped into the wp solr command, see an example:

$ wp solr
usage: wp solr check-server-settings
or: wp solr delete [<id>...] [--all]
   or: wp solr index [--batch=<batch>] [--batch_size=<size>] [--post_type=<post-type>]
            or: wp solr info [--field=<field>] [--format=<format>]
                  or: wp solr optimize-index
                  or: wp solr repost-schema
                  or: wp solr stats [--field=<field>] [--format=<format>]

                        See 'wp help solr <command>' for more information on a specific command.

You can see more details about the commands using wp help solr:

**NAME**

wp solr

**DESCRIPTION**

Perform a variety of actions against your Solr instance.

**SYNOPSIS**

wp solr <command>

   **SUBCOMMANDS**

   check-server-settings Check server settings.
   delete Remove one or more posts from the index.
   index Index all posts for a site.
   info Report information about Solr Power configuration.
   optimize-index Optimize the Solr index.
   repost-schema Repost schema.xml to Solr.
   stats Report stats about indexed content.<h3>WP_Query Integration</h3>

To support searching by author name (e.g. where “Pantheon” would return posts authored by the “Pantheon” user), add the following to your custom schema.xml:

`

Add the following to schema.xml:

  <!-- Add to <types> -->
  <!-- See: https://lucene.apache.org/solr/6_2_0/solr-core/org/apache/solr/schema/TrieDateField.html -->
  <fieldType name="tdate" class="solr.TrieDateField" omitNorms="true" precisionStep="6" positionIncrementGap="0" />

  <!-- Add to <fields> -->
  <field name="post_date_iso" type="tdate" indexed="true" stored="true" required="true" />

Add the following to your functions.php file.

  < ? php
  /**
   * Hooks into the document build process to add post date field in proper format.
   */
  function my_solr_build_document($doc, $post_info) {
     $post_time = strtotime($post_info - > post_date);
     // Matches format required for TrieDateField
     $doc - > setField('post_date_iso', gmdate('c\Z', $post_time));
     return $doc;
  }
  add_filter('solr_build_document', 'my_solr_build_document', 10, 2);

  /**
   * Hooks into query processor, Dismax, to add publish date boost.
   * See: https://www.metaltoad.com/blog/date-boosting-solr-drupal-search-results
   */
  function my_solr_dismax_query($dismax) {
     $dismax - > setQueryParser('edismax');
     $dismax - > setBoostQuery('recip(abs(ms(NOW/HOUR,post_date_iso),3.16e-11,1,1))');
     return $dismax;
  }
  add_filter('solr_dismax_query', 'my_solr_dismax_query');
load more v
65%

Note: the site hash is generated based on the base_url by a function called "apachesolr_site_hash()" once and then it's stored in a variable in your database. So if your sites are sharing the base_url or the database, they will share the Site Hash. In this case, you may need to add another filter (e.g.: Domain ID if using the Domain Access module)., In case you are using the Apache Solr Multisite Search module, you may need the following code to avoid any impacts to the multisite search:,I bashed my head into the wall a bit on this one... it turns out it was not working becuase my sites started out as clones of the same database... which means they all had the same site hash.,This is because ApacheSolr generates a random site_hash and stores it in the variable table. So, if you clone the site, then all of its clones will have the same value for apachesolr_site_hash() which will cause you to see results from all sites.

Drupal 6

function mymodule_apachesolr_modify_query( & $query, & $params, $caller) {
   $query - > add_filter('hash', apachesolr_site_hash());
}

In case you are using the Apache Solr Multisite Search module, you may need the following code to avoid any impacts to the multisite search:

function mymodule_apachesolr_modify_query( & $query, & $params, $caller) {
   if ($caller != "apachesolr_multisitesearch") {
      $query - > add_filter('hash', apachesolr_site_hash());
   }
}

The hook and method names were changed up for D7, so the code to get the same filter behavior should be:

function mymodule_apachesolr_query_alter($query) {
   $query - > addFilter('hash', apachesolr_site_hash());
}

Drupal 6

function mymodule_apachesolr_delete_index_alter( & $query) {
   $query = 'hash:'.apachesolr_site_hash();
}

Drupal 7

function mymodule_apachesolr_delete_by_query( & $query) {
   $query = 'hash:'.apachesolr_site_hash();
}
load more v
75%

This brings us to another interesting topic. What is the format that you accept? JSON, XML, EDIFACT, or just a good old CSV? Do you have an API or a form upload? What do you do with data that has not been updated for years?,You could have a repeating cronjob, that collects this information and adds it directly at the product data so that there is no need to look this up during rendering of the product detail page.,You also may have to deal with the fact of aged stock information, so that an item was bought on your platform, but is not available anymore at the merchant, resulting in order cancellations and changes.,How do you handle this? This has been solved for books by using the ISBN, and if you are the biggest marketplace in the world, you have the power to create an ASIN - you won’t have that power being a small marketplace.

DELETE products

PUT products / _bulk ? refresh {
   "index": {}
} {
   "title": "Elastic Robot T-Shirt",
   "size": "M",
   "color": "gray"
} {
   "index": {}
} {
   "title": "Elastic Robot T-Shirt",
   "size": "S",
   "color": "gray"
} {
   "index": {}
} {
   "title": "Elastic Robot T-Shirt",
   "size": "L",
   "color": "gray"
} {
   "index": {}
} {
   "title": "Elastic Robot T-Shirt",
   "size": "M",
   "color": "green"
} {
   "index": {}
} {
   "title": "Elastic Robot T-Shirt",
   "size": "S",
   "color": "green"
} {
   "index": {}
} {
   "title": "Elastic Robot T-Shirt",
   "size": "L",
   "color": "green"
}
load more v
40%

params — Represents an array of the parameters for the query. It will have a value for everything modified in the query form — from indents to queries to writers.,Clicking “Execute Query” will give the “Nintendo” search results with this addition at the bottom:,By clicking into collection1, we now see that there are 845 documents loaded.,If you want to learn more, drop us a line at hello@blendinteractive.com.

                            java - jar start.jar
load more v

Other "search-undefined" queries related to "Faceted Search (solr) vs Good old filtering via PHP?"