here's a really really rough "take 2" at the problem.
The general idea is to take a smaller "baby-step" as Mike calls it, to the problem.
Really we have been working our way towards this anyway, exposing additional statistics,
making Similarity per-field, fixing up inconsistencies... and this is the way I prefer, as we
get things actually committed and moving.
So whatever is in this patch (which is full of nocommits, but all tests pass and all queries work with it),
we could possibly then split up into other issues and continue slowly proceeding, or maybe
create a branch, whatever.
My problem with the other patch is it requires a ton more work to make any progress on it...
and things don't even compile with it, forget about tests.
The basics here are to:
- Split the "matching" and "scoring calculations" of Scorer. All responsibility of calculations belongs
in the Similarity, the Scorer should be matching positions, working docsEnums, etc etc.
- Similarity as we know it now, gets a more low-level API, and TFIDFSimilarity implements this API,
but exposes its customizations via the tf(), idf(), etc we know now.
- Things like score-caching and specialization of calculations are the responsibility of the Similarity,
as these depend upon the formula being used. For TFIDFSimilarity, i added some optimizations here,
for example it specializes its norms == null case away to remove the per-doc "if".
- Since all Weights create PerReaderTermState (<-- this one needs a new name), to separate the
seeking/stats collection from the calculations, i also optimized PhraseQuery's Weight/Scorer construction
to be single-pass.
Also I like to benchmark every step of the way, so we don't come up with
this design that won't be performant: here are the scores for lucene's default Sim with the patch:
|spanNear([unit, state], 10, true)
|doctimesecnum:[10000 TO 60000]
All Lucene/Solr tests pass, but there are lots of nocommits, especially
- No Javadocs
- Explains need to be fixed: in general the explanation of "matching" belongs where it is now,
but the explanation of "score calculations" belongs in the Similarity.
- need to refactor more out of Weight, currently we pass it to the docscorer, but
its the wrong object, as it can only "hold" a single float.
Anyway, its gonna take some time to rough all this out I'm sure, but I wanted
to show some progress/invite ideas, and also show we can do this stuff
without losing performance.
I have separate patches that need to be integrated/relevance tested e.g.
for average doc length... maybe i'll do that next so we can get some concrete
alternate sims in here before going any further.