diff --git a/search/engine/solr/classes/document.php b/search/engine/solr/classes/document.php index f428dee5e26..24710467858 100644 --- a/search/engine/solr/classes/document.php +++ b/search/engine/solr/classes/document.php @@ -63,17 +63,25 @@ class document extends \core_search\document { 'solr_fileid' => array( 'type' => 'string', 'stored' => true, - 'indexed' => false + 'indexed' => true ), 'solr_filecontenthash' => array( 'type' => 'string', 'stored' => true, - 'indexed' => false + 'indexed' => true ), + // Stores the status of file indexing. 'solr_fileindexedcontent' => array( 'type' => 'int', 'stored' => true, 'indexed' => true + ), + // Field to index, but not store, file contents. + 'solr_filecontent' => array( + 'type' => 'text', + 'stored' => false, + 'indexed' => true, + 'mainquery' => true ) ); diff --git a/search/engine/solr/classes/engine.php b/search/engine/solr/classes/engine.php index 4fe1f7db4eb..9ccaa784028 100644 --- a/search/engine/solr/classes/engine.php +++ b/search/engine/solr/classes/engine.php @@ -234,7 +234,7 @@ class engine extends \core_search\engine { $fields = $documentclass::get_default_fields_definition(); $dismax = false; - if ($query instanceof SolrDisMaxQuery) { + if ($query instanceof \SolrDisMaxQuery) { $dismax = true; } @@ -764,6 +764,11 @@ class engine extends \core_search\engine { // This will prevent solr from automatically making fields for every tika output. $url->param('uprefix', 'ignored_'); + // Control how content is captured. This will keep our file content clean of non-important metadata. + $url->param('captureAttr', 'true'); + // Move the content to a field for indexing. + $url->param('fmap.content', 'solr_filecontent'); + // These are common fields that matches the standard *_point dynamic field and causes an error. $url->param('fmap.media_white_point', 'ignored_mwp'); $url->param('fmap.media_black_point', 'ignored_mbp'); diff --git a/search/engine/solr/tests/engine_test.php b/search/engine/solr/tests/engine_test.php index 2e05935099c..319cb0a2ce6 100644 --- a/search/engine/solr/tests/engine_test.php +++ b/search/engine/solr/tests/engine_test.php @@ -165,6 +165,11 @@ class search_solr_engine_testcase extends advanced_testcase { $this->assertEquals($USER->id, $results[0]->get('userid')); $this->assertEquals(\context_system::instance()->id, $results[0]->get('contextid')); + // Do a test to make sure we aren't searching non-query fields, like areaid. + $querydata->q = \core_search\manager::generate_areaid('core_mocksearch', 'role_capabilities'); + $this->assertCount(0, $this->search->search($querydata)); + $querydata->q = 'message'; + sleep(1); $beforeadding = time(); sleep(1);