From 68530cc61b32ec4e204fddcf975fc0ef17dbb71a Mon Sep 17 00:00:00 2001 From: bshuttle Date: Wed, 29 Mar 2006 10:47:46 +0000 Subject: [PATCH] - add phrase splitter - add test harness for phrase splitter - use boolean + and phrases in searchabletext criterion. --- lib/browse/Criteria.inc | 15 ++++++++++++++- lib/util/ktutil.inc | 28 ++++++++++++++++++++++++++++ tests/util/ktutil/testPhraseSplit.php | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 tests/util/ktutil/testPhraseSplit.php diff --git a/lib/browse/Criteria.inc b/lib/browse/Criteria.inc index ac52bad..4b41916 100644 --- a/lib/browse/Criteria.inc +++ b/lib/browse/Criteria.inc @@ -609,7 +609,20 @@ class SearchableTextCriterion extends BrowseCriterion { $p = array(); $p[0] = "MATCH(DST.document_text) AGAINST (? $boolean_mode)"; - $p[1] = $aRequest[$this->getWidgetBase()]; + + $RESTRICTING_SEARCH = true; + + if ($RESTRICTING_SEARCH) { + // FIXME use a more reasonable approach for splitting this... + $q_set = KTUtil::phraseSplit($aRequest[$this->getWidgetBase()]); + $temp = $q_set; + foreach ($temp as $k => $v) { + $q_set[$k] = sprintf('+"%s"', $v); + } + $p[1] = implode(' ',$q_set); + } else { + $p[1] = $aRequest[$this->getWidgetBase()]; + } return $p; } diff --git a/lib/util/ktutil.inc b/lib/util/ktutil.inc index 0add312..b2cb188 100644 --- a/lib/util/ktutil.inc +++ b/lib/util/ktutil.inc @@ -540,6 +540,34 @@ class KTUtil { return ((float) $microtime_simple[1] + (float) $microtime_simple[0]); } + function phraseSplit($sSearchString) { + $a = preg_split('#"#', $sSearchString); + $i = 0; + $phrases = array(); + $word_parts = array(); + foreach ($a as $part) { + if ($i%2 == 0) { + $word_parts[] = $part; + } else { + $phrases[] = $part; + } + $i += 1; + } + + $words = array(); + foreach ($word_parts as $part) { + $w = (array) explode(' ', $part); + foreach ($w as $potential) { if (!empty($potential)) { $words[] = $potential; }} + } + + + return array( + 'words' => $words, + 'phrases' => $phrases, + ); + + } + } ?> diff --git a/tests/util/ktutil/testPhraseSplit.php b/tests/util/ktutil/testPhraseSplit.php new file mode 100644 index 0000000..7360b0b --- /dev/null +++ b/tests/util/ktutil/testPhraseSplit.php @@ -0,0 +1,40 @@ +'; + + $test = $t[0]; + $phrases = $t[1]; + $words = $t[2]; + + + $p_expect = implode(', ', $phrases); + $w_expect = implode(', ',$words); + + $res = KTUtil::phraseSplit($test); + + $p_got = implode(', ', $res['phrases']); + $w_got = implode(', ', $res['words']); + + + if (($w_got == $w_expect) && ($p_got == $p_expect)) { + print sprintf("Passed: %s\n", $test); + } else { + print "--------\n"; + print sprintf("failed: %s\n", $test); + print sprintf("Phrases - got \"%s\", expected \"%s\"\n", $p_got, $p_expect); + print sprintf("Words - got \"%s\", expected \"%s\"\n", $w_got, $w_expect); + print "--------\n"; + } +} + +?> \ No newline at end of file -- libgit2 0.21.4