silverstripe / silverstripe-fulltextsearch

Adds external full text search engine support to Silverstripe
BSD 3-Clause "New" or "Revised" License
44 stars 83 forks source link

New model field added to index, but doesn't appear in Solr #356

Closed muppsy007 closed 8 months ago

muppsy007 commented 8 months ago

I have inherited an older Silverstripe 3.7 site, running version 2.5 of this module. Working well.

This model that the Index uses is being extended to have a new field called "Hidden".

class Tour extends Product
{
    private static $db = [
        'TourName' => 'Varchar(50)',
        'TourDescription' => 'HTMLText',
        'TourLengthDays' => 'Int',
        'Hidden' => 'Boolean',  // <--- New field added
    ];
}

I have added this new field to the existing Index:

class TourIndex extends SolrIndex {
    function init() {
        $this->addClass('Tour');

        // Fields for searching
        $this->addFulltextField('TourName');
        $this->addFulltextField('TourDescription');

        // Fields we filter on
        $this->addFilterField('TourLengthDays', 'Int');
        $this->addFilterField('Hidden', 'Boolean');
    }
}

I then run the following process:

  1. Delete public_html/.solr
  2. sake /dev/tasks/Solr_Configure
  3. sake /dev/tasks/Solr_Reindex

No errors on either task. Output from both looks as it usually does. However when I look at the Schema Browser in Solr, Hidden is not present. Same thing if I manually open ./solr/TourIndex/conf/schema.xml. The new field is just not there. I have tried changing the type passed to $this->addFilterField('Hidden', 'Int'); but no difference.

Am I missing a step? I can't see another config file relating to existing fields anywhere.

muppsy007 commented 8 months ago

Update: I stepped debugged Solr_Configure locally and I see it using renderWith() on schema.ss. When I inspect the string in that, it most definately shows the new field being added.

<field name='VivaTour_TourLengthDays' type='tint' indexed='true' stored='true' multiValued=''/>
<field name='VivaTour_Hidden' type='boolean' indexed='true' stored='true' multiValued=''/>

But it doesn't appear in the final schema.xml when running the task on Production. But I was running the commands via CLI instead of browser. When I repeated the process and ran them in browser, the index was all good. I imagine a template cache thing between CLI and Browser.