Browse Source

search for alliance and characters too

raylu 12 years ago
parent
commit
1b81975f1f
7 changed files with 52 additions and 18 deletions
  1. 13 4
      db/queries.py
  2. 7 1
      db/schema.sql
  3. 3 0
      importer.py
  4. 5 0
      web/static/css/search.ccss
  5. 1 1
      web/static/js/kill.js
  6. 19 8
      web/static/js/search.js
  7. 4 4
      web/templates/search.html

+ 13 - 4
db/queries.py

@@ -3,12 +3,21 @@ import operator
 import db
 
 def search(q):
+	like_str = '{}%'.format(q)
 	with db.cursor() as c:
+		alliances = db.query(c, '''
+			SELECT DISTINCT alliance_id, alliance_name FROM characters
+			WHERE alliance_name LIKE ? LIMIT 25
+			''', like_str)
 		corps = db.query(c, '''
 			SELECT DISTINCT corporation_id, corporation_name FROM characters
-			WHERE corporation_name LIKE ?
-			''', '%{}%'.format(q))
-	return {'corporations': corps}
+			WHERE corporation_name LIKE ? LIMIT 25
+			''', like_str)
+		chars = db.query(c, '''
+			SELECT DISTINCT character_id, character_name FROM characters
+			WHERE character_name LIKE ? LIMIT 25
+			''', like_str)
+	return {'alliances': alliances, 'corporations': corps, 'characters': chars}
 
 def corporation(corp_id):
 	with db.cursor() as c:
@@ -20,7 +29,7 @@ def corporation(corp_id):
 			JOIN kill_costs ON kill_costs.kill_id = kills.kill_id
 			JOIN eve.mapSolarSystems ON solar_system_id = solarSystemID
 			JOIN eve.mapRegions ON mapSolarSystems.regionID = mapRegions.regionID
-			WHERE corporation_id = ?
+			WHERE corporation_id = ? LIMIT 100
 			''', corp_id)
 		kill_ids = list(map(operator.itemgetter('kill_id'), kills))
 		char_rows = db.query(c, '''

+ 7 - 1
db/schema.sql

@@ -30,7 +30,13 @@ CREATE TABLE `characters` (
 	`security_status` float DEFAULT NULL,
 	`weapon_type_id` int DEFAULT NULL,
 	PRIMARY KEY (`id`),
-	CONSTRAINT `fk_char_km` FOREIGN KEY (`kill_id`) REFERENCES `kills` (`kill_id`)
+	CONSTRAINT `fk_char_km` FOREIGN KEY (`kill_id`) REFERENCES `kills` (`kill_id`),
+	INDEX `character_id` (`character_id`),
+	INDEX `character_name` (`character_name`),
+	INDEX `alliance_id` (`alliance_id`),
+	INDEX `alliance_name` (`alliance_name`),
+	INDEX `corporation_id` (`corporation_id`),
+	INDEX `corporation_name` (`corporation_name`),
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 
 CREATE TABLE `items` (

+ 3 - 0
importer.py

@@ -18,6 +18,9 @@ def insert_kill(c, kill):
 			print('duplicate:', kill['killID'])
 			return
 		raise
+	except TypeError:
+		print(kill)
+		raise
 
 	victim = kill['victim']
 	parambatch = [(

+ 5 - 0
web/static/css/search.ccss

@@ -0,0 +1,5 @@
+#wrapper:
+	padding: 20px
+
+h2:
+	margin-top: 0

+ 1 - 1
web/static/js/kill.js

@@ -178,7 +178,7 @@ window.addEvent('domready', function() {
 			ykill.portrait(char['weapon_type_id'], char['weapon_name'], 'type', '_32.png')
 		);
 		tr.grab(td);
-		tr.grab(new Element('td').appendText(char['damage']));
+		tr.grab(new Element('td').appendText(char['damage'].toLocaleString()));
 
 		table.grab(tr);
 	}

+ 19 - 8
web/static/js/search.js

@@ -1,15 +1,26 @@
 window.addEvent('domready', function() {
 	document.title += ' - search';
 	ykill.api('/search' + document.location.search, function(results) {
-		var corps = $('corps');
-		results.corporations.each(function(corp) {
-			corps.adopt(
-				new Element('a', {
-					'html': corp.corporation_name,
-					'href': '/corporation/' + corp.corporation_id,
-				}),
-				new Element('br')
+		var wrapper = $('wrapper');
+		Object.each(results, function(list, key) {
+			if (!list.length)
+				return;
+			var div = new Element('div').grab(
+				new Element('h2', {'html': key[0].toUpperCase() + key.substr(1)})
 			);
+			var key_singular = key.substr(0, key.length-1)
+			var name_key = key_singular + '_name';
+			var id_key = key_singular + '_id';
+			list.each(function(entity) {
+				div.adopt(
+					new Element('a', {
+						'html': entity[name_key],
+						'href': '/' + key_singular + '/' + entity[id_key],
+					}),
+					new Element('br')
+				);
+			});
+			wrapper.grab(div);
 		});
 	});
 });

+ 4 - 4
web/templates/search.html

@@ -4,9 +4,9 @@
 	<script src="/static/js/search.js"></script>
 {% end %}
 
-{% block main %}
-
-<h2>Corporations</h2>
-<div id="corps"></div>
+{% block css %}
+	<link rel="stylesheet" type="text/css" href="/css/search.css" />
+{% end %}
 
+{% block main %}
 {% end %}