Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SolrIndex->getRequireFiltersComponent does not sanitise class names #247

Open
tyrannosaurusjames opened this issue Apr 3, 2019 · 2 comments

Comments

@tyrannosaurusjames
Copy link

tyrannosaurusjames commented Apr 3, 2019

I am receiving an error from Solr when trying to filter results on the Content field of SiteTree. Specifically:

org.apache.solr.common.SolrException: undefined field SilverStripeCMSModelSiteTree_Content

I am adding the filter by using the SearchQuery class, like so: (simplified example)

$query = new SearchQuery();
$query->addFilter(SiteTree::class . '_Content', 'filter text');

$index->search($query);

It looks like this issue is caused due to a missing call to SolrIndex->sanitiseClassName in SolrIndex->getRequireFiltersComponent.

You can see an example of where the field name is being sanitised correctly in SolrIndex->getExcludeFiltersComponent here: https://github.com/silverstripe/silverstripe-fulltextsearch/blob/master/src/Solr/SolrIndex.php#L965-L970 which is what lead me to believe it was missing in getRequireFiltersComponent

Edit: I am using silverstripe/fulltextsearch version 3.4.1 but this issue appears to affect newer versions too

@tyrannosaurusjames
Copy link
Author

I should note I can workaround this issue by sanitising the class name myself before I call SearchQuery->addFilter, e.g.

$query = new SearchQuery();
$fieldName = SiteTree::class . '_Content';
$sanitisedFieldName = (new MySolrIndex())->sanitiseClassName($fieldName);

$query->addFilter($sanitisedFieldName, 'filter text');

@emteknetnz
Copy link
Member

Related #269

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants