| 105 | return [search_text, filters] |
| 106 | |
| 107 | def actionFeedSearch(self, to, search, limit=30, day_limit=30): |
| 108 | if "ADMIN" not in self.site.settings["permissions"]: |
| 109 | return self.response(to, "FeedSearch not allowed") |
| 110 | |
| 111 | from Site import SiteManager |
| 112 | rows = [] |
| 113 | stats = [] |
| 114 | num_sites = 0 |
| 115 | total_s = time.time() |
| 116 | |
| 117 | search_text, filters = self.parseSearch(search) |
| 118 | |
| 119 | for address, site in SiteManager.site_manager.list().items(): |
| 120 | if not site.storage.has_db: |
| 121 | continue |
| 122 | |
| 123 | if "site" in filters: |
| 124 | if filters["site"].lower() not in [site.address, site.content_manager.contents["content.json"].get("title").lower()]: |
| 125 | continue |
| 126 | |
| 127 | if site.storage.db: # Database loaded |
| 128 | feeds = site.storage.db.schema.get("feeds") |
| 129 | else: |
| 130 | try: |
| 131 | feeds = site.storage.loadJson("dbschema.json").get("feeds") |
| 132 | except: |
| 133 | continue |
| 134 | |
| 135 | if not feeds: |
| 136 | continue |
| 137 | |
| 138 | num_sites += 1 |
| 139 | |
| 140 | for name, query in feeds.items(): |
| 141 | s = time.time() |
| 142 | try: |
| 143 | db_query = DbQuery(query) |
| 144 | |
| 145 | params = [] |
| 146 | # Filters |
| 147 | if search_text: |
| 148 | db_query.wheres.append("(%s LIKE ? OR %s LIKE ?)" % (db_query.fields["body"], db_query.fields["title"])) |
| 149 | search_like = "%" + search_text.replace(" ", "%") + "%" |
| 150 | params.append(search_like) |
| 151 | params.append(search_like) |
| 152 | if filters.get("type") and filters["type"] not in query: |
| 153 | continue |
| 154 | |
| 155 | if day_limit: |
| 156 | db_query.wheres.append( |
| 157 | "%s > strftime('%%s', 'now', '-%s day')" % (db_query.fields.get("date_added", "date_added"), day_limit) |
| 158 | ) |
| 159 | |
| 160 | # Order |
| 161 | db_query.parts["ORDER BY"] = "date_added DESC" |
| 162 | db_query.parts["LIMIT"] = str(limit) |
| 163 | |
| 164 | res = site.storage.query(str(db_query), params) |