Earlier quoted context omitted.
this trend of `a: float` always reminds me of the Rich Hickey "you don't want types, you want proper names" talk. I really hate this (feels to me Go inspired) tendency of undescriptive single letter variable, with the type system abused as a naming assistant. Names can convey proper semantic information about what your program does, use them godammit
> tendency of undescriptive single letter variable There are 2 schools of thought on which one is clearer, F = G * m1 * m2 / r**2 or force = gravitational_constant * mass_of_body_1 * mass_of_body_2 / distance_between_bodies ** 2
A search engine in 80 lines of Python
81–90 of 100 posts
Re: A search engine in 80 lines of Python
#82Earlier quoted context omitted.
Phycisist : > F = G * m1 * m2 / r**2 Computer scientist: nonrelativistic_gravitational_force = ( Physics.NonRelativistic.Gravity.gravitational_constant * body1.NonRelativistic.mass() * body2.NonRelativistic.mass() / body1.NonRelativistic.distanceTo(body2) ** 2 )*
Software engineer straight out of uni: # Get force of gravity as below to be used later F = G * m1 * m2 / r*2 Software engineer 5 years after uni: gravitational_force = ( PhysicsContextConstructorFactory.createByRelativisticEnum(SystemConfig.getRelativisticEnum()).construct().getGravitationalConstant().value() * body1.getRelativisticContext(SystemConfig.getRelativisticEnum()).mass().value() * body2.getRelativisticCon…
Re: A search engine in 80 lines of Python
#83This is really cool. I have a pretty fast BM25 search engine in Pandas I've been working on for local testing. https://github.com/softwaredoug/searcharray Why Pandas? Because BM25 is one thing, but you also want to combine with other factors (recency, popularity, etc) easily computed in pandas / numpy... BTW phrases are the hard thing. There are a lot of edge case in phrase matching. Not to mention slop, etc. And you…
Hey, I tackled phrase matching in my toy project here: https://github.com/vasilionjea/lofi-dx/blob/main/test/search... I think I tested it thoroughly but any feedback would be appreciated! Edit: I delta-encoded and base36-encoded the positions
Re: A search engine in 80 lines of Python
#84Don't use keywords (1-grams), the best results for English can be achieved with 2+3-grams. n-grams retain context.
I think you'd probably get the best result with both. There's definitely real merit to a keyword-understanding of which terms appear in the title or as a named entity for example.
Re: A search engine in 80 lines of Python
#85Re: A search engine in 80 lines of Python
#86Earlier quoted context omitted.
Software engineer straight out of uni: # Get force of gravity as below to be used later F = G * m1 * m2 / r*2 Software engineer 5 years after uni: gravitational_force = ( PhysicsContextConstructorFactory.createByRelativisticEnum(SystemConfig.getRelativisticEnum()).construct().getGravitationalConstant().value() * body1.getRelativisticContext(SystemConfig.getRelativisticEnum()).mass().value() * body2.getRelativisticCon…
Sadly the 5y SE forgot about dependency injecting the computation... after all we're always on the brink of new physics discovery, we'd hate to have to rewrite all that code when we can readily swap in fresh laws with the proper architecture!
Re: A search engine in 80 lines of Python
#87What is the point of flexing about LOC, if it is not a total number of \r\n since we are using external deps? I know that there is no unit for codebase in SI system, but I think we should measure cognitive load somehow.
Although it's not formal, my team sometimes says "this code is not grug" or "this code is pretty grug" in reference to https://grugbrain.dev
Re: A search engine in 80 lines of Python
#88Re: A search engine in 80 lines of Python
#89Imo, it's not fair to talk about 80 lines of code while using thitd party libraries (feedparser, bs4, etc)
Re: A search engine in 80 lines of Python
#90Looking at the code (src/microsearch/engine.py), we have: class SearchEngine: def __init__(self, k1: float = 1.5, b: float = 0.75): self._index: dict[str, dict[str, int]] = defaultdict(lambda: defaultdict(int)) self._documents: dict[str, str] = {} self.k1 = k1 self.b = b I've no idea what `k1` or `b` are. Nor is there a single comment in the entire file. Are comments considered unfashionable these days? Looking at `_…