Last active
June 17, 2017 11:52
-
-
Save ivmarkp/46f71c445e2fcb81fa6e1a5cb2273186 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/xapian-applications/omega/Makefile.am b/xapian-applications/omega/Makefile.am | |
index ae10f2ad6e2b..0393b6fa6c0b 100644 | |
--- a/xapian-applications/omega/Makefile.am | |
+++ b/xapian-applications/omega/Makefile.am | |
@@ -181,7 +181,7 @@ libtransform_la_LIBADD = $(PCRE_LIBS) | |
omega_SOURCES = omega.cc query.cc cgiparam.cc utils.cc configfile.cc date.cc\ | |
cdb_init.cc cdb_find.cc cdb_hash.cc cdb_unpack.cc jsonescape.cc loadfile.cc\ | |
datevalue.cc common/str.cc sample.cc urlencode.cc weight.cc expand.cc\ | |
- csvescape.cc timegm.cc | |
+ csvescape.cc timegm.cc md5.cc md5wrap.cc | |
# Not currently used, and we ought to handle non-Unix perms too: unixperm.cc | |
omega_LDADD = $(XAPIAN_LIBS) libtransform.la | |
diff --git a/xapian-applications/omega/docs/omegascript.rst b/xapian-applications/omega/docs/omegascript.rst | |
index 942172424c81..039c52f662e1 100644 | |
--- a/xapian-applications/omega/docs/omegascript.rst | |
+++ b/xapian-applications/omega/docs/omegascript.rst | |
@@ -417,6 +417,11 @@ $prettyurl{URL} | |
URL for displaying to the user (rather than in links), but which should | |
still work if copied and pasted. | |
+$qid{TEXT} | |
+ unique ID for the query TEXT which would be usually taken from $query. | |
+ This command uses MD5 hashing algorithm to produce a 128-bit hash for | |
+ the given query text which is used as a unique ID. | |
+ | |
$query[{PREFIX}] | |
list of query strings for prefix PREFIX. Any tab characters in the | |
query strings are converted to spaces before adding them to the list | |
diff --git a/xapian-applications/omega/omegatest b/xapian-applications/omega/omegatest | |
index bbc60c95787f..dd9fed3e3d02 100755 | |
--- a/xapian-applications/omega/omegatest | |
+++ b/xapian-applications/omega/omegatest | |
@@ -414,6 +414,12 @@ printf '$highlight{$cgi{text},$cgi{list},$cgi{open},$cgi{close}}' > "$TEST_TEMPL | |
testcase 'A list of <b>words</b>' list="words" text="A list of words" open="<b>" close="</b>" | |
testcase 'A *list* of *words*' list="words${tab}list" text="A list of words" open="*" close="*" | |
+# Feature tests for $qid{} | |
+printf '$qid{$cgi{qtext}}' > "$TEST_TEMPLATE" | |
+testcase 'd41d8cd98f00b204e9800998ecf8427e' qtext="" | |
+testcase '098f6bcd4621d373cade4e832627b4f6' qtext="test" | |
+testcase 'b4c216e4da73d1d01277ef46d0514821' qtext="simple query" | |
+ | |
rm "$OMEGA_CONFIG_FILE" "$TEST_INDEXSCRIPT" "$TEST_TEMPLATE" | |
rm -rf "$TEST_DB" | |
if [ "$failed" = 0 ] ; then | |
diff --git a/xapian-applications/omega/query.cc b/xapian-applications/omega/query.cc | |
index ac3854893e25..c0df0e5d044a 100644 | |
--- a/xapian-applications/omega/query.cc | |
+++ b/xapian-applications/omega/query.cc | |
@@ -69,6 +69,7 @@ | |
#include "values.h" | |
#include "weight.h" | |
#include "expand.h" | |
+#include "md5wrap.h" | |
#include <xapian.h> | |
@@ -976,6 +977,7 @@ CMD_pack, | |
CMD_percentage, | |
CMD_prettyterm, | |
CMD_prettyurl, | |
+CMD_qid, | |
CMD_query, | |
CMD_querydescription, | |
CMD_queryterms, | |
@@ -1107,6 +1109,7 @@ T(pack, 1, 1, N, 0), // convert a number to a 4 byte big endian binary strin | |
T(percentage, 0, 0, N, 0), // percentage score of current hit | |
T(prettyterm, 1, 1, N, Q), // pretty print term name | |
T(prettyurl, 1, 1, N, 0), // pretty version of URL | |
+T(qid, 1, 1, N, 0), // query ID for entered query | |
T(query, 0, 1, N, Q), // query | |
T(querydescription,0, 0, N, M), // query.get_description() (run_query() adds filters so M) | |
T(queryterms, 0, 0, N, Q), // list of query terms | |
@@ -1167,6 +1170,18 @@ write_all(int fd, const char * buf, size_t count) | |
return 0; | |
} | |
+static void trim_string(string & s) | |
+{ | |
+ string::size_type first_non_whitespace = s.find_first_not_of(' '); | |
+ if (first_non_whitespace == string::npos) { | |
+ s.resize(0); | |
+ return; | |
+ } | |
+ string::size_type first_index = first_non_whitespace; | |
+ string::size_type last_index = s.find_last_not_of(' '); | |
+ s = s.substr(first_index, last_index - first_index + 1); | |
+} | |
+ | |
static string | |
eval(const string &fmt, const vector<string> ¶m) | |
{ | |
@@ -1938,6 +1953,19 @@ eval(const string &fmt, const vector<string> ¶m) | |
value = args[0]; | |
url_prettify(value); | |
break; | |
+ case CMD_qid: { | |
+ string qstr = args[0]; | |
+ trim_string(qstr); | |
+ string md5, hexhash; | |
+ md5_string(qstr.c_str(), md5); | |
+ for (size_t i = 0; i < md5.size(); ++i) { | |
+ char buf[16]; | |
+ sprintf(buf, "%02x", static_cast<unsigned char>(md5[i])); | |
+ hexhash += buf; | |
+ } | |
+ value = hexhash; | |
+ break; | |
+ } | |
case CMD_query: { | |
pair<multimap<string, string>::const_iterator, | |
multimap<string, string>::const_iterator> r; | |
diff --git a/xapian-applications/omega/templates/query b/xapian-applications/omega/templates/query | |
index a9002bef9f98..138ff7baa52a 100644 | |
--- a/xapian-applications/omega/templates/query | |
+++ b/xapian-applications/omega/templates/query | |
@@ -106,7 +106,7 @@ $if{$field{size},<span title="$html{$field{size}} bytes">Size: <b>$html{$filesiz | |
</div> | |
</div> | |
</td> | |
-<td><b><a href="$html{$field{url}}">$html{$or{$field{caption},$field{title},$prettyurl{$field{url}},Untitled}}</a></b><br> | |
+<td><b><a href="$html{omega?FMT=$url{clicklog}&QUERYID=&url{$qid{$query}}&DOCID=$url{$field{$id}}&URL=$url{$field{url}}}">$html{$or{$field{caption},$field{title},$prettyurl{$field{url}},Untitled}}</a></b><br> | |
<small>$snippet{$field{sample}}</small><br> | |
<a href="$html{$field{url}}">$html{$field{url}}</a><br> | |
<small> | |
@@ -153,3 +153,4 @@ $map{$cgilist{B},<input type=hidden name=B value="$html{$_}">} | |
</body> | |
</html> | |
$log{query.log} | |
+$if{$query, $log{search.log, "$qid{$query}\t""$csv{$query, 1}\t""[$hitlist{$list{$id,$. }}]\t""$topdoc"}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment