Fix the levels viewer: markers were drawn on whichever plan was showing
This commit is contained in:
@@ -23,6 +23,14 @@ logger = logging.getLogger(__name__)
|
||||
search_bp = Blueprint('search', __name__)
|
||||
|
||||
|
||||
# EVERY searcher below truncates with .limit(). An unordered LIMIT lets the
|
||||
# database return a DIFFERENT subset of the matching rows between two identical
|
||||
# requests - the same search run twice came back with different hits, which reads
|
||||
# as the search being broken rather than as a missing ORDER BY. Each query
|
||||
# therefore ends with a TOTAL order: a display key plus the primary key, so ties
|
||||
# cannot reorder. Relevance is applied afterwards in Python, over a stable set.
|
||||
|
||||
|
||||
def _word_match(query, *columns):
|
||||
"""SQL clause matching rows that contain EVERY word of the query, each word
|
||||
in any of the columns, in any order.
|
||||
@@ -213,7 +221,7 @@ def _search_applications(query, search_term):
|
||||
apps = Application.query.filter(
|
||||
Application.isactive == True,
|
||||
_word_match(query, Application.appname, Application.appdescription)
|
||||
).limit(10).all()
|
||||
).order_by(Application.appname, Application.appid).limit(10).all()
|
||||
|
||||
for app in apps:
|
||||
relevance = 20
|
||||
@@ -258,7 +266,8 @@ def _search_knowledgebase(query, search_term):
|
||||
KnowledgeBase.appid.notin_(retired)),
|
||||
_word_match(query, KnowledgeBase.shortdescription,
|
||||
KnowledgeBase.keywords)
|
||||
).limit(20).all()
|
||||
).order_by(KnowledgeBase.clicks.desc(),
|
||||
KnowledgeBase.linkid).limit(20).all()
|
||||
|
||||
for kb in kb_articles:
|
||||
relevance = 10 + (kb.clicks or 0) * 0.1
|
||||
@@ -378,7 +387,7 @@ def _search_assets(query, search_term):
|
||||
_word_match(query, Asset.assetnumber, Asset.name,
|
||||
Asset.serialnumber, Asset.notes,
|
||||
Asset.gaugelabreference, Asset.maintenancereference)
|
||||
).limit(15).all()
|
||||
).order_by(Asset.assetnumber, Asset.assetid).limit(15).all()
|
||||
|
||||
for asset in assets:
|
||||
relevance = 15
|
||||
@@ -421,7 +430,7 @@ def _search_measuringtools(query, search_term):
|
||||
Asset.isactive == True,
|
||||
_word_match(query, Asset.assetnumber, Asset.name,
|
||||
Asset.serialnumber, Asset.gaugelabreference)
|
||||
).limit(15).all()
|
||||
).order_by(Asset.assetnumber, Asset.assetid).limit(15).all()
|
||||
|
||||
for asset in assets:
|
||||
relevance = 15
|
||||
@@ -461,7 +470,8 @@ def _search_usbdevices(query, search_term):
|
||||
USBDevice.isactive == True,
|
||||
_word_match(query, USBDevice.serialnumber, USBDevice.assetnumber,
|
||||
USBDevice.label, USBDevice.productname)
|
||||
).limit(10).all()
|
||||
).order_by(USBDevice.serialnumber,
|
||||
USBDevice.usbdeviceid).limit(10).all()
|
||||
|
||||
for device in devices:
|
||||
relevance = 20
|
||||
@@ -507,7 +517,8 @@ def _search_printeditems(query, search_term):
|
||||
PrintedItem.isactive == True,
|
||||
_word_match(query, PrintedItem.itemcode, PrintedItem.gagelabtag,
|
||||
PrintedItem.itemname, PrintedItem.itemdescription)
|
||||
).limit(10).all()
|
||||
).order_by(PrintedItem.itemcode,
|
||||
PrintedItem.printeditemid).limit(10).all()
|
||||
|
||||
for item in items:
|
||||
relevance = 20
|
||||
@@ -563,7 +574,7 @@ def _search_customfields(query, search_term):
|
||||
CustomField.searchable == True,
|
||||
CustomField.isactive == True,
|
||||
_word_match(query, CustomFieldValue.value),
|
||||
).limit(15).all()
|
||||
).order_by(Asset.assetnumber, CustomField.fieldid).limit(15).all()
|
||||
|
||||
for asset, field in rows:
|
||||
result = _get_asset_result(asset, query, relevance=40)
|
||||
@@ -583,7 +594,8 @@ def _search_by_ip(query, search_term):
|
||||
).options(
|
||||
joinedload(Communication.asset).joinedload(Asset.assettype),
|
||||
joinedload(Communication.asset).joinedload(Asset.location),
|
||||
).limit(10).all()
|
||||
).order_by(Communication.ipaddress,
|
||||
Communication.communicationid).limit(10).all()
|
||||
|
||||
seen_assets = set()
|
||||
for comm in comms:
|
||||
@@ -643,7 +655,7 @@ def _search_hostnames(query, search_term):
|
||||
).options(
|
||||
joinedload(Computer.asset).joinedload(Asset.assettype),
|
||||
joinedload(Computer.asset).joinedload(Asset.location),
|
||||
).limit(10).all()
|
||||
).order_by(Computer.hostname, Computer.computerid).limit(10).all()
|
||||
|
||||
for comp in computers:
|
||||
if comp.asset and comp.asset.isactive:
|
||||
@@ -666,7 +678,7 @@ def _search_hostnames(query, search_term):
|
||||
).options(
|
||||
joinedload(Printer.asset).joinedload(Asset.assettype),
|
||||
joinedload(Printer.asset).joinedload(Asset.location),
|
||||
).limit(10).all()
|
||||
).order_by(Printer.hostname, Printer.printerid).limit(10).all()
|
||||
|
||||
for printer in printers:
|
||||
if printer.asset and printer.asset.isactive:
|
||||
@@ -689,7 +701,8 @@ def _search_hostnames(query, search_term):
|
||||
).options(
|
||||
joinedload(NetworkDevice.asset).joinedload(Asset.assettype),
|
||||
joinedload(NetworkDevice.asset).joinedload(Asset.location),
|
||||
).limit(10).all()
|
||||
).order_by(NetworkDevice.hostname,
|
||||
NetworkDevice.networkdeviceid).limit(10).all()
|
||||
|
||||
for device in devices:
|
||||
if device.asset and device.asset.isactive:
|
||||
@@ -773,7 +786,7 @@ def _search_vendor_model_type(query, search_term):
|
||||
Asset.isactive == True,
|
||||
_word_match(query, Vendor.vendor, Model.modelnumber,
|
||||
MachineType.machinetype)
|
||||
).limit(10).all()
|
||||
).order_by(Asset.assetnumber, Asset.assetid).limit(10).all()
|
||||
|
||||
for asset in machine_assets:
|
||||
results.append(_get_asset_result(asset, query, 30))
|
||||
@@ -801,7 +814,7 @@ def _search_vendor_model_type(query, search_term):
|
||||
Asset.isactive == True,
|
||||
_word_match(query, Vendor.vendor, Model.modelnumber,
|
||||
PrinterType.printertype)
|
||||
).limit(10).all()
|
||||
).order_by(Asset.assetnumber, Asset.assetid).limit(10).all()
|
||||
|
||||
for asset in printer_assets:
|
||||
results.append(_get_asset_result(asset, query, 30))
|
||||
@@ -827,7 +840,7 @@ def _search_vendor_model_type(query, search_term):
|
||||
Asset.isactive == True,
|
||||
_word_match(query, Vendor.vendor,
|
||||
NetworkDeviceType.networkdevicetype)
|
||||
).limit(10).all()
|
||||
).order_by(Asset.assetnumber, Asset.assetid).limit(10).all()
|
||||
|
||||
for asset in netdev_assets:
|
||||
results.append(_get_asset_result(asset, query, 30))
|
||||
|
||||
Reference in New Issue
Block a user