Moved the search engine config settings out into a separate file.

master
Pacman Ghost 4 years ago
parent ea9999054b
commit 57c547a220
  1. 63
      asl_articles/config/app.cfg
  2. 67
      asl_articles/config/search.cfg
  3. 59
      asl_articles/search.py

@ -4,66 +4,3 @@
; https://github.com/lxml/lxml/blob/master/src/lxml/html/defs.py
;HTML_ATTR_WHITELIST =
;HTML_TAG_WHITELIST =
[Search weights]
; This section defines the relative weights of the searchable fields (see _SEARCHABLE_COL_NAMES).
; Each hit in a field scores 1 point, unless otherwise specified otherwise here.
tags = 10
name = 5
name2 = 3
authors = 5
[Search aliases]
; This section defines search term aliases.
; For example, the entry "a = b ; c" means that searching for "a" will become "( a OR b OR c )".
; NOTE: Searching for "b" or "c" will be unaffected.
latw = atmm ; atr ; baz ; mol-p ; mol-projector ; piat ; pf ; pfk ; psk
sw = support weapon ; lmg ; mmg ; hmg ; mtr ; mortar ; dc ; ft ; radio ; phone ; rcl ; atmm ; atr ; baz ; mol-p ; mol-projector ; piat ; pf ; pfk ; psk
fortifications = cave ; a-t ditch ; foxhole ; sangar ; trench ; bunker ; minefield ; mines ; booby trap ; panji ; pillbox ; roadblock ; tetrahedron ; wire
vehicles = tank ; halftrack ; half-track ; jeep ; carrier
illumination = starshell ; illuminating round ; trip flare
[Search aliases 2]
; This section defines search term aliases.
; For example, the entry "a = b = c" means that searching for any of "a" or "b" or "c" will all become "( a OR b OR c )".
asl = Advanced Squad Leader
mmp = Multi-Man Publishing = Multiman Publishing
ah = Avalon Hill
vftt = View From The Trenches
dftb = Dispatches From The Bunker
ch = Critical Hit
aslj = ASL Journal
rb = red barricades
votg = valor of the guards
kgp = kampfgrupper peiper
kgs = kampfgrupper scherer
brt = br:t = blood reef tarawa
pb = pegasus bridge
dc = demo charge
ft = flamethrower
baz = bazooka
pf = panzerfaust
psk = panzershreck
wp = white phosphorous
mol = molotov cocktail
ovr = overrun
cc = close combat
thh = tank-hunter hero
scw = shaped-charge weapon
; NOTE: We can't define "sw" here since we've defined it above.
; sw = support weapon
mg = machinegun = machine gun
ammo = ammunition
lc = landing craft
ht = halftrack
wa = wall advantage
hob = heat of battle
cg = campaign game
firelane = fire-lane = fire lane
firegroup = fire-group = fire group
armor = armour
humor = humour

@ -0,0 +1,67 @@
[Search weights]
; This section defines the relative weights of the searchable fields (see _SEARCHABLE_COL_NAMES).
; Each hit in a field scores 1 point, unless otherwise specified otherwise here.
tags = 10
name = 5
name2 = 3
authors = 5
[Search aliases]
; This section defines search term aliases.
; For example, the entry "a = b ; c" means that searching for "a" will become "( a OR b OR c )".
; NOTE: Searching for "b" or "c" will be unaffected.
latw = atmm ; atr ; baz ; mol-p ; mol-projector ; piat ; pf ; pfk ; psk
sw = support weapon ; lmg ; mmg ; hmg ; mtr ; mortar ; dc ; ft ; radio ; phone ; rcl ; atmm ; atr ; baz ; mol-p ; mol-projector ; piat ; pf ; pfk ; psk
fortifications = cave ; a-t ditch ; foxhole ; sangar ; trench ; bunker ; minefield ; mines ; booby trap ; panji ; pillbox ; roadblock ; tetrahedron ; wire
entrenchments = foxhole ; trench ; ditch
vehicles = tank ; halftrack ; half-track ; jeep ; carrier
illumination = starshell ; illuminating round ; trip flare
[Search aliases 2]
; This section defines search term aliases.
; For example, the entry "a = b = c" means that searching for any of "a" or "b" or "c" will all become "( a OR b OR c )".
asl = Advanced Squad Leader
mmp = Multi-Man Publishing = Multiman Publishing
ah = Avalon Hill
vftt = View From The Trenches
dftb = Dispatches From The Bunker
ch = Critical Hit
aslj = ASL Journal
rb = red barricades
votg = valor of the guards
kgp = kampfgrupper peiper
kgs = kampfgrupper scherer
brt = br:t = blood reef tarawa
pb = pegasus bridge
dc = demo charge
ft = flamethrower
baz = bazooka
pf = panzerfaust
psk = panzershreck
wp = white phosphorous
mol = molotov cocktail
ovr = overrun
cc = close combat
thh = tank-hunter hero
scw = shaped-charge weapon
; NOTE: We can't define "sw" here since we've defined it above.
; sw = support weapon
mg = machinegun = machine gun
ammo = ammunition
lc = landing craft
ht = halftrack
wa = wall advantage
hob = heat of battle
cg = campaign game
pbm = pbem
firelane = fire-lane = fire lane
firegroup = fire-group = fire group
armor = armour
humor = humour

@ -542,34 +542,35 @@ def init_search( session, logger ):
for article in session.query( Article ).order_by( Article.time_created.desc() ):
add_or_update_article( dbconn, article, session )
# load the search aliases
fname = os.path.join( asl_articles.config_dir, "app.cfg" )
_logger.debug( "Loading search aliases: %s", fname )
cfg = AppConfigParser( fname )
global _search_aliases
_search_aliases = _load_search_aliases(
cfg.get_section( "Search aliases" ),
cfg.get_section( "Search aliases 2" )
)
# load the search weights
_logger.debug( "Loading search weights:" )
global _search_weights
for row in cfg.get_section( "Search weights" ):
if row[0] not in _SEARCHABLE_COL_NAMES:
asl_articles.startup.log_startup_msg( "warning",
"Unknown search weight field: {}", row[0],
logger = _logger
)
continue
try:
_search_weights[ row[0] ] = float( row[1] )
_logger.debug( "- %s = %s", row[0], row[1] )
except ValueError:
asl_articles.startup.log_startup_msg( "warning",
"Invalid search weight for \"{}\": {}", row[0], row[1],
logger = _logger
)
# configure the searcg engine
fname = os.path.join( asl_articles.config_dir, "search.cfg" )
if os.path.isfile( fname ):
# load the search aliases
_logger.debug( "Loading search aliases: %s", fname )
cfg = AppConfigParser( fname )
global _search_aliases
_search_aliases = _load_search_aliases(
cfg.get_section( "Search aliases" ),
cfg.get_section( "Search aliases 2" )
)
# load the search weights
_logger.debug( "Loading search weights:" )
global _search_weights
for row in cfg.get_section( "Search weights" ):
if row[0] not in _SEARCHABLE_COL_NAMES:
asl_articles.startup.log_startup_msg( "warning",
"Unknown search weight field: {}", row[0],
logger = _logger
)
continue
try:
_search_weights[ row[0] ] = float( row[1] )
_logger.debug( "- %s = %s", row[0], row[1] )
except ValueError:
asl_articles.startup.log_startup_msg( "warning",
"Invalid search weight for \"{}\": {}", row[0], row[1],
logger = _logger
)
# load the author aliases
# NOTE: These should really be stored in the database, but the UI would be so insanely hairy,
@ -602,7 +603,7 @@ def _load_search_aliases( aliases, aliases2 ):
"Found duplicate search alias: {}", key,
logger = _logger
)
search_aliases[ key ] =vals
search_aliases[ key ] = vals
# load the search aliases
for row in aliases:

Loading…
Cancel
Save