diff options
-rw-r--r-- | app/controllers/application.rb | 8 | ||||
-rw-r--r-- | todo.txt | 14 | ||||
-rw-r--r-- | vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb | 24 |
3 files changed, 27 insertions, 19 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 0f151874a..e36d21e22 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -6,7 +6,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: application.rb,v 1.43 2008-04-30 01:42:39 francis Exp $ +# $Id: application.rb,v 1.44 2008-04-30 02:14:07 francis Exp $ class ApplicationController < ActionController::Base @@ -161,11 +161,7 @@ class ApplicationController < ActionController::Base @search_results = xapian_object.results @search_hits = xapian_object.matches_estimated @search_spelling = xapian_object.spelling_correction - - # Calculate simple word highlighting view code for users and public bodies - query_nopunc = @query.gsub(/[^a-z0-9]/i, " ") - query_nopunc = query_nopunc.gsub(/\s+/, " ") - @highlight_words = query_nopunc.split(" ") + @highlight_words = xapian_object.words_to_highlight end # URL generating functions are needed by all controllers (for redirects), @@ -1,19 +1,15 @@ -Add PCTs to categories Museum aliases Internet explorer bug with HTML for Elena +Test: Add PCTs to categories +Test: http://localhost:3000/list - sent highlighted here deployment: change the exec_after scripts to not do solr - rebuild the xapian index install it on the server + rebuild the xapian index make sure solr is stopped -http://localhost:3000/list - sent highlighted here - -highlight word docs text -full_search still has html_highlight parameter - You need to reload Xapian processes after any change how do we deal with that? - maybe reload xapian db every x searches? @@ -27,8 +23,10 @@ Later Solr ---------- Search for "health" crashes it (Solr?) + +highlight word docs text Remove vendor/plugins/acts_as_solr -remove all the solr plugins and stuff +Finally check no solr in source grep -i, or in find (filenames) FOI requests to use to test it ============================== diff --git a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb index b3a7a6342..0befd8bbe 100644 --- a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb +++ b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb @@ -4,7 +4,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: acts_as_xapian.rb,v 1.15 2008-04-30 01:19:53 francis Exp $ +# $Id: acts_as_xapian.rb,v 1.16 2008-04-30 02:14:07 francis Exp $ # TODO: # Test :eager_load @@ -45,9 +45,10 @@ # field is returned. Along with a count of how many there are in total. # acts_as_solr doesn't have this. # -# * No highlighting - Xapian can't return you text highlighted with a search query. -# You can try and make do with TextHelper::highlight. I found the highlighting -# in acts_as_solr didn't really understand the query anyway. +# * No highlighting - Xapian can't return you text highlighted with a search +# query. You can try and make do with TextHelper::highlight (combined with +# words_to_highlight below). I found the highlighting in acts_as_solr didn't +# really understand the query anyway. # # * Date range searching - maybe this works in acts_as_solr, but I never found # out how. @@ -306,6 +307,7 @@ module ActsAsXapian attr_accessor :limit attr_accessor :query attr_accessor :matches + attr_accessor :query_string # Note that model_classes is not only sometimes useful here - it's essential to make sure the # classes have been loaded, and thus acts_as_xapian called on them, so @@ -316,6 +318,7 @@ module ActsAsXapian sort_by_prefix = options[:sort_by_prefix] || nil sort_by_ascending = options[:sort_by_ascending] || true collapse_by_prefix = options[:collapse_by_prefix] || nil + self.query_string = query_string ActsAsXapian.readable_init if ActsAsXapian.db.nil? @@ -324,7 +327,7 @@ module ActsAsXapian # Construct query which only finds things from specified models model_query = Xapian::Query.new(Xapian::Query::OP_OR, model_classes.map{|mc| "M" + mc.to_s}) - user_query = ActsAsXapian.query_parser.parse_query(query_string, + user_query = ActsAsXapian.query_parser.parse_query(self.query_string, Xapian::QueryParser::FLAG_BOOLEAN | Xapian::QueryParser::FLAG_PHRASE | Xapian::QueryParser::FLAG_LOVEHATE | Xapian::QueryParser::FLAG_WILDCARD | Xapian::QueryParser::FLAG_SPELLING_CORRECTION) @@ -368,6 +371,17 @@ module ActsAsXapian return correction end + # Return just normal words in the query, not ones in date ranges or similar + # Use this for cheap highlighting with TextHelper::highlight, and excerpt. + def words_to_highlight + query_nopunc = self.query_string.gsub(/[^a-z0-9:\.\/]/i, " ") + query_nopunc = query_nopunc.gsub(/\s+/, " ") + words = query_nopunc.split(" ") + # Remove anything with a :, . or / in it + words = words.find_all {|o| !o.match(/(:|\.|\/)/) } + return words + end + # Return array of models found def results # Pull out all the results |