[Xapian-discuss] Omega and Wildcards

James Aylett james-xapian at tartarus.org
Sat Jan 31 13:19:35 GMT 2009


Forwarded from chrysn at fsfe.org, due to list problems.

------------------

taking up an issue of 2007, when ken loafman asked about using omega
with wildcards, i've extended his patch with a configuration option and
appropriate documentation updates, and would like to suggest that for
inclusion in omega.

the configuration reader was extended to take an option `wildcards on`,
which results in parse_query to be given
`Xapian::QueryParser::FLAG_WILDCARD` as a flag.

as the default is `off`, existing configurations will not be affected
unless they explicitly enable this option.

the patch is against svn /trunk/xapian-applications/omega revision
11818.

i hope this can be included; the reason why i need this is that ikiwiki
uses omega, and this is the only reasonable way to use wildcard searches
in ikiwiki.


regards
chrysn


ps: sorry if this appears on the list in duplicate; after signing up for
  the list, i tried to revoke the mail pending moderator approval and
  re-send it as a list member.

-----------------

diff --git a/configfile.cc b/configfile.cc
index 24e3965..d901442 100644
--- a/configfile.cc
+++ b/configfile.cc
@@ -42,6 +42,7 @@ string database_dir = "/var/lib/omega/data/";
 string template_dir = "/var/lib/omega/templates/";
 string log_dir = "/var/log/omega/";
 string cdb_dir = "/var/lib/omega/cdb/";
+bool allow_wildcards = false;
 
 /** Return true if the file fname exists.
  */
@@ -94,6 +95,14 @@ try_read_config_file(const char * cfile)
 	    log_dir = value + "/";
 	} else if (name == "cdb_dir") {
 	    cdb_dir = value + "/";
+	} else if (name == "wildcards") {
+	    if (value == "on") {
+	        allow_wildcards = true;
+	    } else if (value == "off") {
+	        allow_wildcards = false;
+	    } else {
+	        throw string("Bad wildcards in configuration file `") + cfile + "' (may be on or off)";
+	    }
 	}
     }
 
diff --git a/configfile.h b/configfile.h
index b2cc962..d636486 100644
--- a/configfile.h
+++ b/configfile.h
@@ -30,6 +30,7 @@ extern string database_dir;
 extern string template_dir;
 extern string log_dir;
 extern string cdb_dir;
+extern bool allow_wildcards;
 
 void read_config_file();
 
diff --git a/docs/overview.rst b/docs/overview.rst
index 023186b..c1d24aa 100644
--- a/docs/overview.rst
+++ b/docs/overview.rst
@@ -372,14 +372,16 @@ is a '#', omega treats the line as a comment and ignores it.
 
 The current options are 'database_dir' (the directory containing all the
 Omega databases), 'template_dir' (the directory containing the OmegaScript
-templates), and 'log_dir' (the directory which the OmegaScript $log command
-writes log files to).
+templates), 'log_dir' (the directory which the OmegaScript $log command
+writes log files to), and 'wildcards' (setting which to on results in wildcards
+to be accepted in search queries).
 
 The default values (used if no configuration file is found) are::
 
  database_dir /var/lib/omega/data
  template_dir /var/lib/omega/templates
  log_dir /var/log/omega
+ wildcards off
 
 Note that, with apache, environment variables may be set using mod_env, and
 with apache 1.3.7 or later this may be used inside a .htaccess file.  This
diff --git a/query.cc b/query.cc
index 7781ce4..6c61df4 100644
--- a/query.cc
+++ b/query.cc
@@ -233,7 +233,7 @@ set_probabilistic(const string &oldp)
     }
 
     try {
-	query = qp.parse_query(query_string);
+	query = qp.parse_query(query_string, ( allow_wildcards ? Xapian::QueryParser::FLAG_WILDCARD : 0 ));
     } catch (Xapian::QueryParserError &e) {
 	error_msg = e.get_msg();
 	return BAD_QUERY;



More information about the Xapian-discuss mailing list