From b6e5e749b321edd7ee5bbe9d0639cb7b470aa967 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 9 Jun 2011 14:42:02 -0700 Subject: [PATCH] Add a fuzzy structured query template. --- lib/es/widgets.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/es/widgets.js b/lib/es/widgets.js index 1f57ff80..a4096f7f 100644 --- a/lib/es/widgets.js +++ b/lib/es/widgets.js @@ -1398,6 +1398,12 @@ highqual = row.find(".es-highqual").val(); if(lowqual.length) value[row.find(".es-lowop").val()] = lowqual; if(highqual.length) value[row.find(".es-highop").val()] = highqual; + } else if(op === "fuzzy") { + var qual = row.find(".es-qual").val(), + fuzzyqual = row.find(".es-fuzzyqual").val(); + + if(qual.length) value["value"] = qual; + if(fuzzyqual.length) value[row.find(".es-fuzzyop").val()] = fuzzyqual; } else { value = row.find(".es-qual").val(); } @@ -1424,7 +1430,7 @@ _changeQueryField_handler: function(jEv) { var select = $(jEv.target); var spec = select.children(":selected").data("spec"); - select.siblings().remove(".es-op,.es-qual,.es-range"); + select.siblings().remove(".es-op,.es-qual,.es-range,.es-fuzzy"); var ops = []; if(spec.type === 'match_all') { } else if(spec.type === '_all') { @@ -1444,11 +1450,13 @@ _changeQueryOp_handler: function(jEv) { var op = $(jEv.target), opv = op.val(); - op.siblings().remove(".es-qual,.es-range"); - if(opv === 'term' || opv === 'wildcard' || opv === 'prefix' || opv === 'fuzzy' || opv === "query_string") { + op.siblings().remove(".es-qual,.es-range,.es-fuzzy"); + if(opv === 'term' || opv === 'wildcard' || opv === 'prefix' || opv === "query_string") { op.after({ tag: "INPUT", cls: "es-qual", type: "text" }) } else if(opv === 'range') { op.after(this._range_template()); + } else if(opv === 'fuzzy') { + op.after(this._fuzzy_template()); } }, @@ -1482,6 +1490,14 @@ { tag: "SELECT", cls: "es-highop", children: ["to", "lt", "lte"].map(acx.ut.option_template) }, { tag: "INPUT", type: "text", cls: "es-highqual" }, ]}; + }, + + _fuzzy_template: function() { + return { tag: "SPAN", cls: "es-fuzzy", children: [ + { tag: "INPUT", cls: "es-qual", type: "text" }, + { tag: "SELECT", cls: "es-fuzzyop", children: ["max_expansions", "min_similarity"].map(acx.ut.option_template) }, + { tag: "INPUT", cls: "es-fuzzyqual", type: "text" } + ]}; } });