Here is the first lines of:
Here is the dependencies:
According to the, the entry point of the web application, is . The main problem with searx is that it is not easy to use it as library.
Looking upyield only 13 routes:
Let's look through each from least interesting to the most clever, that is approximately a bottom-up read.
Here is the full content of that route:
There is two small issues with this code:
It is easier to debug code whenis followed by a simple variable e.g. . Here things are made worse, because the returned value span multiple lines.
the top-down left-right you need to zigzag and reconfigure your brain to also do read down-top (and even right-left in more problematic cases).is multiple line statement. That requires to zigzag the code. Instead of reading
The use of underscoresin variable names is odd. In this case, it is a way to avoid to think and overload the reader with useless and poorly named variables names. I do that a lot with Scheme, but with Scheme you can use more readable and better looking characters for naming variables. underscore is difficult to read, and sometime it disappears because of poor resolution or image scaling. The following code:
Can be reworked into a list comprehension:
That much more obvious that one can use a list comprehension instead of the following code:
Mind the use ofas variable name. When used as variable name placeholder, should not be accessed. It would be trivial to replace with and bundle it inside a list comprehension.
That is a complex one-liner:
I will not repeat that multi-line return statements are difficult to read.
In that case, the code is trivial enough, but nesting calls is a evil habit. Things like:
Are not only difficult to read (even with normal variable names) but also more complex to debug, because the intermediate an result does not get their own variable.
That is nice code. I like the following pattern that is used twice in that function:
It is odd to see the HTTP method spelled lower case but that might be something specific to opensearch. Otherwise I try to avoid shortcut variables names in that functionand could both be renamed since it is the output of the function.
Not very interesting, except maybe it would be easier to create a global constant (and in some case, but prolly not here, use an external text file).
Again, factoring the body of theand using a list comprehension could be nice.
The following code:
That is equivalent to:
Nothing interesting to say about this function.
The following code:
Can be rewritten to be more readable with a comprehension:
I still do not understand why everybody use the variable name.
Can be rewritten:
I will not repeat what I already wrote about comprehensions. There is good pattern in there. But the last line of the function kills everything:
The above is already too tall for function body!
An idea here about how to avoid to use aand sadly hide the interesting logic away from the where the action happens:
That is necessarily a side-effect because it does not assign a variable otherwise it would be dead-code. Hereis mutated, mutable objects are difficult to debug.
Following the spirit of the code, the functioncould be a method of especially since it is used only once in the whole code base.
Anyway the full function could rewritten as follow:
Mind the fact:
I dropped thevariable, because I am not sure where it is useful.
It is not clear what happens in the lastloop especially with the mutated raw query, so I replaced the whole thing with a comprehension and factored the body in a function called .
But that is not everything we can do. To make the project usable as a library, it will be nice to extract the logic and keep environment specifics in the flask view.
If you do it yourself, you might end up with something like that as the view function:
It is a static page so not much to say, except the indentation is not good.
That is the gist of the project. Here is the big problem: validation, logic and rendering is mixed into a giant view function, factorization was done, but there is room for more especially regarding the output generation.
Here is the code that execute the meta search:
There is no point into defining asthe first three variables since it is useless without an actual result, the code that follow expect something that is not .
Something that is always odd: multiples statements inside theblock. At the very least, it should be something along the line of:
Note that the output, this time is inside a single function called.
Another possible approach would be flat/ like:
The body of the original/ block does not look good:
How meta search works wit searx?
After jumping around definitions I end in the classat the method :
It does trigger simultaneously, using threads, a search query against a search engine based on user preference and the lastblock will retrieve the result under a timeout. That is if a search engine does not reply under less that some configured time, it is considered an error.
The part that interest me is:
After some jumping around, I find the mighty directorythat contains all the logic to query and scrape results .
This is a very quick rework of searx, one might call it a tribute to searx since it is very far from as feature parity.