| Conditions | 1 |
| Total Lines | 67 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # -*- coding: utf-8 -*- |
||
| 24 | @staticmethod |
||
| 25 | def _compute_keyword_queries(terms): |
||
| 26 | search_on = dict( |
||
| 27 | description=[ |
||
| 28 | 'description', |
||
| 29 | 'description.technologies' |
||
| 30 | ], |
||
| 31 | title=[ |
||
| 32 | 'title', |
||
| 33 | 'title.technologies' |
||
| 34 | ], |
||
| 35 | company=['company'] |
||
| 36 | ) |
||
| 37 | |||
| 38 | description_query = Q( |
||
| 39 | 'multi_match', |
||
| 40 | type='most_fields', |
||
| 41 | query=terms, |
||
| 42 | fields=search_on['description'], |
||
| 43 | fuzziness='AUTO', |
||
| 44 | operator='or', |
||
| 45 | minimum_should_match='1<2 2<2 3<3 4<3 5<4 6<5 7<5 8<6 9<6', |
||
| 46 | boost=len(terms.split(',')) |
||
| 47 | ) |
||
| 48 | |||
| 49 | title_query = Q( |
||
| 50 | 'multi_match', |
||
| 51 | type='most_fields', |
||
| 52 | query=terms, |
||
| 53 | fields=search_on['title'], |
||
| 54 | fuzziness='AUTO', |
||
| 55 | operator='or', |
||
| 56 | minimum_should_match='1<1', |
||
| 57 | boost=20 - len(terms.split(',')) + 1 |
||
| 58 | ) |
||
| 59 | |||
| 60 | company_name_query = Q( |
||
| 61 | 'multi_match', |
||
| 62 | type='best_fields', |
||
| 63 | query=terms, |
||
| 64 | fields=search_on['company'], |
||
| 65 | fuzziness='AUTO', |
||
| 66 | operator='or', |
||
| 67 | minimum_should_match='1<1', |
||
| 68 | boost=50 |
||
| 69 | ) |
||
| 70 | |||
| 71 | keyword_queries = Q( |
||
| 72 | 'bool', |
||
| 73 | must=[ |
||
| 74 | company_name_query |
||
| 75 | ], |
||
| 76 | should=[ |
||
| 77 | title_query, |
||
| 78 | description_query |
||
| 79 | ] |
||
| 80 | ) | Q( |
||
| 81 | 'bool', |
||
| 82 | must=[ |
||
| 83 | description_query |
||
| 84 | ], |
||
| 85 | should=[ |
||
| 86 | title_query, |
||
| 87 | company_name_query |
||
| 88 | ] |
||
| 89 | ) |
||
| 90 | return keyword_queries |
||
| 91 | |||
| 201 |