Hello,

Thanks for your answer, I'll try to be clearer.

We have a plugin, we've been usint it with solr 7.3.1 and are now upgrading
to solr 9.2.1

The plugin is declared like this in solrconfig.xml

<lib path="/var/solr/data/lib/lbs-function.jar" />
<valueSourceParser name="stopwordsw"
class="com.mappy.lbs.solr.search.function.StopWordSubtypeValueSourceParser"
   stopwords="le;la;les;"    startswith="3"    />

    <query>        <listener event="newSearcher"
class="com.mappy.lbs.solr.search.function.StopWordSubtypeLoader" />
    </query>

What we want is the plugin to read values
    stopwords="le;la;les;"    startswith="3"

At startup.

So we have a class



public class StopWordSubtypeLoader extends AbstractSolrEventListener {

        @Override
        public void newSearcher(SolrIndexSearcher newSearcher,
SolrIndexSearcher currentSearcher) {
                // Here code to read values
        }
}

In solr 7.3.1, function newSearcher was called at startup and we
loaded values stopwords and startswith in newSearcher, but it doesn't
work in solr 9.2.1, the function newSearcher is not called at startup

We fixed it be moving the code to load values in class constructor


        public StopWordSubtypeLoader(SolrCore core) {
                super(core);
                SolrConfig config = core.getSolrConfig();
                for (PluginInfo p :
config.getPluginInfos("org.apache.solr.search.ValueSourceParser")) {
                        if (p.name.equals(this.name)) {
                                String[] stopWords = 
p.attributes.get("stopwords").split(";");
                                StopWordSubtypeLoader.stopWords = new
HashSet<String>(Arrays.asList(stopWords));
                                StopWordSubtypeLoader.startsWithValue =
Integer.parseInt(p.attributes.get("startswith"));
                                LOGGER.info("StopWordSubtypeLoader: Loading 
stopwords value " +
StopWordSubtypeLoader.stopWords);
                                LOGGER.info("StopWordSubtypeLoader: Loading 
startswith value " +
StopWordSubtypeLoader.startsWithValue);
                                break;
                        }
                }
                if (StopWordSubtypeLoader.stopWords==null){
                        LOGGER.error("StopWordSubtypeLoader: no stopwords 
value");
                }
                if (StopWordSubtypeLoader.startsWithValue==0){
                        LOGGER.error("StopWordSubtypeLoader: startsWithValue = 
0");
                }
        }

but not sure it this is the right solution.

In unit tests, we had

    @BeforeClass
    public static void beforeClass() throws Exception {
        // here we create a test core. You can find the config in
test/resources/solr/collection1/conf/
        initCore("solrconfig.xml","schema.xml");
    }

and newSearcher was called during the initCore execution.


Thanks,

Best regards,

Elisabeth


Le mer. 17 avr. 2024 à 23:52, Chris Hostetter <hossman_luc...@fucit.org> a
écrit :

>
> I'm really confused by your question -- you start off asking about
> AbstractSolrEventListener and the newSearcher event, but then when you
> show us your solrconfig.xml & plugin snippet you are showing us a usage of
> ValueSourceParser -- which doesn't exitend AbstractSolrEventListener --
> and your question seems to be about ValueSourceParser.init() being called
> w/o the arguments you expect.
>
> Can you explain in more depth what it is you are doing and what you expect
> to happen?  (Can you show us your full config + "working" unit test so we
> can understand what you _expect_ to happen in solr)
>
>
> Generally speaking: Solr only fires "newSearcher" events for plugins that
> are registered as "newSearcher listeners" in solrconfig.xml, something
> like this...
>
>     <listener event="newSearcher" class="solr.QuerySenderListener">
>       <arr name="queries">
>         <lst><str name="q">solr</str><str name="sort">price asc</str></lst>
>         <lst><str name="q">rocks</str><str name="sort">weight
> asc</str></lst>
>       </arr>
>     </listener>
>
> ...a custom ValueSourceParser registered via <valueSourceParser ... /> is
> completely ignorant of any newSearcher events -- it will be init()ed once
> during SolrCore init -- and should recieve the args specified in
> solrconfig.xml -- and the parse() will be called each time it is needed.
> If you need information about the SolrIndexSearcher at parse time, you can
> get it from the FunctionQParser (argument) via getReq().getSearcher()
>
>
>
>
> : Date: Tue, 16 Apr 2024 12:11:41 +0200
> : From: elisabeth benoit <elisaelisael...@gmail.com>
> : Reply-To: users@solr.apache.org
> : To: users@solr.apache.org
> : Subject: solr 9.2.1 plugin newSearcher function not called
> :
> : Hello,
> :
> : We have a solr plugin with parameters in solrconfig.xml.
> :
> : In the plugin, we use the newSearcher  function of a class overriding
> :
> : AbstractSolrEventListener
> :
> : to read parameters written in solrconfig.xml.
> :
> : The plugin is working fine but the plugin function newSearcher is not
> : called, so we cant read the parameters.
> :
> : In unit test it's working, but not at runtime, I cant understand why.
> :
> : I've tried another solution that I found in an example in solr source
> code
> :
> : in solrconfig.xml in solr source code
> : <valueSourceParser name="nvl" class=
> : "org.apache.solr.search.function.NvlValueSourceParser">
> : <float name="nvlFloatValue">0.0</float>
> : </valueSourceParser>
> : <initParams path="/select">
> : <lst name="defaults">
> : <str name="df">text</str>
> : </lst>
> : </initParams>
> :
> :
> : reading the values in solr source code
> :
> : public class NvlValueSourceParser extends ValueSourceParser {
> :
> : /** Value to consider "null" when found in a ValueSource Defaults to 0.0
> */
> : private float nvlFloatValue = 0.0f;
> :
> :
> : @Override
> : public void init(NamedList<?> args) {
> : /* initialize the value to consider as null */
> : Float nvlFloatValueArg = (Float) args.get("nvlFloatValue");
> : if (nvlFloatValueArg != null) {
> : this.nvlFloatValue = nvlFloatValueArg;
> : }
> : }
> : }
> :
> : when I do the same in my plugin code, when (in unit tests) code enters
> init
> : function, args is empty.
> :
> : Any help would be welcome!
> :
> : Best regards,
> : Elisabeth
> :
>
> -Hoss
> http://www.lucidworks.com/
>

Reply via email to