MCPcopy Create free account
hub / github.com/amule-project/amule / ParsedSearchExpression

Function ParsedSearchExpression

src/SearchList.cpp:73–152  ·  view source on GitHub ↗

Helper function for lexer.

Source from the content-addressed store, hash-verified

71
72// Helper function for lexer.
73void ParsedSearchExpression(const CSearchExpr* pexpr)
74{
75 int iOpAnd = 0;
76 int iOpOr = 0;
77 int iOpNot = 0;
78
79 for (unsigned int i = 0; i < pexpr->m_aExpr.GetCount(); i++) {
80 const wxString& str = pexpr->m_aExpr[i];
81 if (str == SEARCHOPTOK_AND) {
82 iOpAnd++;
83 } else if (str == SEARCHOPTOK_OR) {
84 iOpOr++;
85 } else if (str == SEARCHOPTOK_NOT) {
86 iOpNot++;
87 }
88 }
89
90 // this limit (+ the additional operators which will be added later) has to match the limit in 'CreateSearchExpressionTree'
91 // +1 Type (Audio, Video)
92 // +1 MinSize
93 // +1 MaxSize
94 // +1 Avail
95 // +1 Extension
96 // +1 Complete sources
97 // +1 Codec
98 // +1 Bitrate
99 // +1 Length
100 // +1 Title
101 // +1 Album
102 // +1 Artist
103 // ---------------
104 // 12
105 if (iOpAnd + iOpOr + iOpNot > 10) {
106 yyerror("Search expression is too complex");
107 }
108
109 _SearchExpr.m_aExpr.Empty();
110
111 // optimize search expression, if no OR nor NOT specified
112 if (iOpAnd > 0 && iOpOr == 0 && iOpNot == 0) {
113 // figure out if we can use a better keyword than the one the user selected
114 // for example most user will search like this "The oxymoronaccelerator 2", which would ask the node which indexes "the"
115 // This causes higher traffic for such nodes and makes them a viable target to attackers, while the kad result should be
116 // the same or even better if we ask the node which indexes the rare keyword "oxymoronaccelerator", so we try to rearrange
117 // keywords and generally assume that the longer keywords are rarer
118 if (/*thePrefs::GetRearrangeKadSearchKeywords() &&*/ !s_strCurKadKeyword.IsEmpty()) {
119 for (unsigned int i = 0; i < pexpr->m_aExpr.GetCount(); i++) {
120 if (pexpr->m_aExpr[i] != SEARCHOPTOK_AND) {
121 if (pexpr->m_aExpr[i] != s_strCurKadKeyword
122 && pexpr->m_aExpr[i].find_first_of(Kademlia::CSearchManager::GetInvalidKeywordChars()) == wxString::npos
123 && pexpr->m_aExpr[i].Find('"') != 0 // no quoted expressions as keyword
124 && pexpr->m_aExpr[i].length() >= 3
125 && s_strCurKadKeyword.length() < pexpr->m_aExpr[i].length())
126 {
127 s_strCurKadKeyword = pexpr->m_aExpr[i];
128 }
129 }
130 }

Callers 1

yyparseFunction · 0.85

Calls 4

yyerrorFunction · 0.85
GetCountMethod · 0.45
IsEmptyMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected