Problem/Motivation

Phrase search ("Is equal to" & "Is not equal to" operators) doesn't work properly with Apache Solr version 6 and above.

Proposed resolution

Phrase searches must be quoted - http://lucene.apache.org/solr/guide/7_1/the-standard-query-parser.html#s... and escaped propely.

Remaining tasks

  1. Patch - Done
  2. Review
  3. Commit

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

TBD

Comments

RoSk0 created an issue. See original summary.

rosk0’s picture

Assigned: rosk0 » Unassigned
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new684 bytes

Initial patch.
Tested on Apache Solr 7.1.

miroslavbanov’s picture

I don't think apachesolr_clean_text() is used like this. As far as I can see it's used on indexing of documents.

miroslavbanov’s picture

Maybe just this:

$phrase = '"' . htmlspecialchars($this->value, ENT_QUOTES) . '"';

Also I'm amazed this module is used in 2019.

rosk0’s picture

Unfortunately it's still in use...

Replaced apachesolr_clean_text() with htmlspecialchars() as suggested.

  • MiroslavBanov committed 864e4c2 on 7.x-1.x authored by RoSk0
    Issue #3074446 by RoSk0: Phrase search doesn't work properly with Apache...
miroslavbanov’s picture

Status: Needs review » Fixed

Thanks for the contribution. Also created a new tag - 7.x-1.1-beta2. Cheers!

rosk0’s picture

Thank you for committing and new release!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

savel’s picture

Sorry to tell, but this fix breaks operator support for phrases.

For example, I'm looking for "Apples" or "Oranges". Currently, I have "Apples OR Oranges" (without quotes) in "Is equal to" filter.
If you add quotes for the phrase, no results returned until I have an entity with type "Apples OR Oranges".

There should be another solution. If there isn't I propose to revert the patch to keep the module usable.

See Operator support is broken for "Is equal to" filter in 7.x-1.1-beta2.

miroslavbanov’s picture

Status: Closed (fixed) » Active

Reverted in dev and reopening this issue. There is no new tag yet.

miroslavbanov’s picture

I reverted, because I thought that existing sites are likely to use old and legacy Solr, so it is less disruptive to revert for now. Ideally there can be a fix that takes into account the other issue. I suppose we can check if there are quotes, and not add quotes in that case. Not sure what to do. Patches welcome.

miroslavbanov’s picture

If the text for the filter is "some value" and the field name is some_field, the "is equal to" operator is building a query like sm_some_field:(some value)

I guess that doesn't work as expected with new solr versions, but it's probably a general limitation because the operators are badly named and not thought out sufficiently. Maybe if we add a new "phrase" operator it can add the quotes, and there would be less confusion or regressions.

Currently there appear to be different use cases to support. Someone may need to make the query type:("apples" OR "oranges"), and someone may need to make the query title:("the quick brown fox"). To support both cases, frankly I don't know what is the best approach, but most important is that I don't want to introduce regressions.