Skip to content

Commit

Permalink
tweak simple search. For non-default searches, if the
Browse files Browse the repository at this point in the history
given spelling matches, show only the given spelling (and not alternates)
  • Loading branch information
funderburkjim committed Feb 6, 2021
1 parent c0a5e5e commit d0d93f3
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 42 deletions.
25 changes: 23 additions & 2 deletions simple-search/v1.1/getword_list_1.0_main.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function getword_list_processone() {
// reset xml, and status
// 11-01-2017. Extra flag to indicate whether this is the user's input word
$ans1['user_key_flag'] = ($dictheadword == $keyparmin_slp1);
#dbgprint(true,"getword: dictheadword = $dictheadword, keyparmin_slp1 = $keyparmin_slp1\n");
# accent-adjustment
#require_once($dirpfx . "accent_adjust.php");
$dictinfo = $getParms->dictinfo;
Expand All @@ -161,15 +162,34 @@ function getword_list_processone() {
#dbgprint(true,"getword_list_1.0_main: #result=" . count($result) . "\n");
$result1a = order_by_wf($result,$wfreqs);
$result1 = put_user_word_first($result1a);
$ans['result']=$result1;
// 02-05-2021: Return ONLY user result if inputparmin is not default,
// and certain other conditions
$result2 = restrict_to_user_word($result1,$inputparmin);
$ans['result']=$result2;

$ru3 = microtime(true); //getrusage();
$utime = $ru3 - $ru2;
dbgprint($dbg,"time used gathering data: $utime s\n");

return $ans;
} // end of getword_list_processone

function restrict_to_user_word($result1,$inputparmin){
if (count($result1) == 0) {
return $result1;
}
if ($inputparmin == 'default') {
return $result1;
}
$ans1 = $result1[0];
if (! $ans1['user_key_flag']) {
return $result1;
}
// Now, the user's spelling was found, and user specified a non-default
// spelling.
// Return ONLY the user's spelling
$result2 = array($ans1);
return $result2;
}
function init_word_frequency() {
# word_frequency_adj.txt removes duplicates from word_frequency.txt
# see readme.org in ../v0.1
Expand Down Expand Up @@ -205,6 +225,7 @@ function wf_cmp($a,$b) {
return ($a['wf'] > $b['wf']) ? -1 : 1;
#return ($a['wf'] > $b['wf']) ? 1 : -1;
}

function put_user_word_first($result) {
$iuser = -1;
$i = 0;
Expand Down
15 changes: 13 additions & 2 deletions simple-search/v1.1/list-0.2s_rw.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
test.key = find_word;
test.url = "getword_list_1.0.php"; // 01-22-2021
test.input = $('#input_simple').val(); //
console.log('list-0.2s_rw: simpleDisplay: test.input=',test.input);
//console.log('list-0.2s_rw: simpleDisplay: test.input=',test.input);
test.output = $('#output').val(); //'deva';
test.dict = $('#dict').val();;
// Blank out result area
Expand Down Expand Up @@ -287,11 +287,22 @@
}
listDisplay(dicthw);
}

displayOption2_error = function(json) {
console.log('displayOption2 error: json=',json);
var html = `<p>Programming error in simple search at displayOption2<br/>
Please notify programmer Funderburk of the error, with your inputs <br/>
at the email at bottom of Sanskrit-lexicon home page.`
$('#simpleinfo').html(html);
}
displayOption2 = function(json) {
// console.log('list-0.2s_rw.php: displayOption2');
// console.log('json=',json);
// 02-05-2021. Prepare for errors (e.g. non-json results)
var results = json['result'];
if (! results) { // results may be undefined
displayOption2_error();
return;
}
var dict = json['dict'];
var nresults = results.length;
var nfound = nresults;
Expand Down
Loading

0 comments on commit d0d93f3

Please sign in to comment.