Documentation > CMS-Drupal > Slow Solr Queries in Drupal

Understanding and Fixing Slow Drupal → Solr Queries

1. What You’re Seeing

Drupal’s Search API and Facet API often generate large, complex Solr queries like this:

?q={!boost b=boost_document} *:* &
fq=(+available:true +display_in_catalog:Yes +(*:* -facet_field:X)) &
facet.field=field_languages &
facet.field=field_formats &
facet.field=field_categories &
facet.limit=-1 &
facet.mincount=1 &
rows=20

The Debug Output (Simplified)

From Solr’s debug section:

  • Total time: ~2000ms
  • Query time: 278ms
  • Faceting time: 1704ms
  • Facet processor: SimpleFacets
  • Facet method: FCS (FieldCache Scanning)
  • Facet fields: 10+
  • Each with: facet.limit=-1, facet.missing=false

So, the query itself is fine — it’s the faceting that eats up most of the runtime.


2. Why It’s Slow

A. The *:* Query Pattern

Drupal often sends {!boost b=boost_document} *:*, meaning “match everything.”
Even with filters, Solr still evaluates the entire index before narrowing results.
That’s expensive, especially on big collections.

B. Many fq Filters

Dozens of filters like:

fq=field_a:valueA
fq=field_b:valueB
fq=(+available:true +display_in_catalog:Yes)

Each one adds cost — especially negations like (*:* -field:value) or range queries like [ * TO * ].

C. Excessive Facets

Fields such as field_language, field_format, field_category, etc. are all requested, often with:

facet.limit = -1
facet.missing = false
facet.sort = count

Each of these facets has to count every term across every matching document. That’s the main bottleneck — the facet block alone took ~1700ms.

D. The FCS (FieldCache) Method

Solr’s FCS method scans the entire field value space. When many documents or multi-valued fields are involved, it’s slow. The newer enum or stream methods, or JSON facets, are more efficient.


3. What to Fix — In Drupal

A. Reduce the Facet Count

In Configuration → Search API → View Modes, disable facets that aren’t visible on the page.
Every active facet triggers Solr work, even if Drupal doesn’t render it.

B. Limit Facet Results

In Facet API settings, set:

facet.limit = 50
facet.mincount = 1

Avoid facet.limit=-1 — that means “return everything.”

C. Avoid facet.missing=false

This setting forces Solr to calculate missing values. Unless your UX needs it, remove it.

D. Use the JSON Facet API

If your Solr core is 7.x or newer, switch Drupal’s Search API backend to use the JSON Facet API.
It’s faster, parallelized, and supports streaming facet counts.

E. Cache Drupal Results

Enable Drupal’s Search API query cache and facet cache.
It prevents Solr from recomputing identical facets for repeated queries.


4. What to Fix — In Solr

A. Enable Filter Cache

Ensure your Solr solrconfig.xml includes:

<filterCache class="solr.FastLRUCache" size="512" initialSize="512" autowarmCount="128"/>

This helps repeated filters (like available:true) resolve instantly.

B. Increase facet.threads

If you must run many facets:

facet.threads=4

Parallelizes field facet computation.

C. Use DocValues

Ensure all facet fields are stored with docValues="true" in the schema:

<field name="field_languages" type="string" stored="true" indexed="true" docValues="true"/>

This speeds up both faceting and sorting.

D. Use JSON Facets or Streaming Facets

Switch from classic facet.field to:

json.facet={
  categories: { type: "terms", field: "field_category", limit: 50 },
  formats: { type: "terms", field: "field_format", limit: 50 }
}

These APIs skip legacy overhead.


5. What’s Actually Happening Internally

From your debug trace:

"facet-debug": {
  "elapse": 1704,
  "processor": "SimpleFacets",
  "appliedMethod": "FCS",
  "inputDocSetSize": 10
}

Even with only 10 returned documents, the facet engine must still traverse the full dataset to count terms. This is why even small result sets can be slow when facets are many or unbounded.


6. Checklist for Optimization

Area Action Typical Gain
Drupal Facet Limit Set facet.limit=50 60–80% faster
Remove facet.missing Disable 5–15% faster
Enable caching Drupal + Solr Big
Use DocValues Schema config Major
Use JSON facets Modern Solr 2–5× faster
Avoid *:* base queries Use tighter filters Major
facet.threads=4 Solr config 20–40% faster

7. Example Fixed Query

Before:

?q={!boost b=boost_document} *:*&facet.limit=-1&facet.field=...

After:

?q=*:*&fq=available:true&fq=display_in_catalog:Yes&
facet.limit=50&
facet.threads=4&
json.facet={
  languages:{type:terms,field:field_language,limit:50},
  formats:{type:terms,field:field_format,limit:50}
}

8. Conclusion

The slowdown isn’t Solr being “slow” — it’s Drupal asking for everything at once.
By trimming unnecessary facets, tightening query filters, and enabling JSON facets with DocValues, you can cut load time by 80–90% without losing functionality.


This tutorial applies to any Drupal + Apache Solr setup where complex facet-heavy queries are generated by the Search API or Facet API modules.






Review us on Google Business
ISO-9001 CERTIFIED ISO-27001 CERTIFIED