Why is this simple Solr highlighting attempt failing?

前端 未结 1 1340
清酒与你
清酒与你 2021-02-09 10:45

I\'ve read the Solr highlighting wiki document several times, searched everywhere, but cannot get even basic highlighting to work with my Solr installation. I am running Solr 3.

1条回答
  •  南笙
    南笙 (楼主)
    2021-02-09 11:12

    The way you're making highlighting seems good, but your solrconfig.xml looks a bit messy. Unfortunately the example you took uses basically all the available options, and I guess you don't need them. Unless you need something different from the default, I'd start commenting out all your highlighting configuration, as well as your default parameters. Then I'd play around with the url parameters you need, just a couple to start: hl=on and hl.fl=title. Once you've found the right parameters you can configure them as default.

    That said, given your title fieldType I suspect it isn't tokenized, unless you changed the default string type definition. In that case your query wouldn't match the title field, that's why you don't get highlighting on it. Are you maybe using edismax (or dismax)? If yes, what is your qf parameter? Is it possible that the toyota term is on another field that matches your query? If you're using edismax you can try searching for q=title:toyota ans see if you get results.

    You can also check where is your match enabling debugQuery=on and checking the debug output.

    UPDATE
    I saw you changed the title fieldType to text_general, but this doesn't change anything because that type isn't tokenized on whitespaces. You haven't told yet what query parser you're using, anyway if I'm right you should use WhitespaceTokenizerFactory instead of the StandardTokenizerFactory:

     
    

    After that, remember to reindex all your data, otherwise you won't see any change. Basically, if you index something like toyota whatever without tokenizing on whitespaces, you won't get any result searching for toyota, and you won't even have toyota highlighted on that field because it doesn't match. My assumption is that you're using dismax or edismax query parser and searching on more than one field, and some of them but not title match your search, that's why you'd get results but not highlighting on title, the only field you selected for highlighting. Can you post the results you get searching for toyota? Is the toyota term on some other fields than title?

    0 讨论(0)
提交回复
热议问题