if obj is None:
obj = super(CachedQuerySet, self).get(*args, **kwargs)
obj.__class__.objects.cache_obj(obj)
- else:
- d = obj.__dict__
return obj
--- /dev/null
+var currentSideBar = 'div#title_side_bar';
+function changeSideBar(enabled_bar) {
+ $(currentSideBar).hide();
+ currentSideBar = enabled_bar;
+ $(currentSideBar).fadeIn('slow');
+
+}
+$(function () {
+ $('div#editor_side_bar').hide();
+ $('div#tags_side_bar').hide();
+
+ $('input#id_title').focus(function(){changeSideBar('div#title_side_bar')});
+ $('textarea#editor').focus(function(){changeSideBar('div#editor_side_bar')});
+ $('input#id_tags').focus(function(){changeSideBar('div#tags_side_bar')});
+});
+
+$(function() {
+ var $input = $('#id_title');
+ var $box = $('#ask-related-questions');
+ var template = $('#question-summary-template').html();
+
+ var results_cache = {};
+
+ function reload_suggestions_box(e) {
+ var q = $input.val().trim();
+
+ if (q.length == 0) {
+ $('#ask-related-questions').html('');
+ return false;
+ }
+
+ if (results_cache[q] && results_cache[q] != '') {
+ $('#ask-related-questions').html(results_cache[q]);
+ return false;
+ }
+
+ $.post(related_questions_url, {title: q}, function(data) {
+ if (data) {
+ var c = $input.val().trim();
+
+ if (c != q) {
+ return;
+ }
+
+ var html = '';
+ for (var i = 0; i < data.length; i++) {
+ var item = template.replace(new RegExp('%URL%', 'g'), data[i].url)
+ .replace(new RegExp('%SCORE%', 'g'), data[i].score)
+ .replace(new RegExp('%TITLE%', 'g'), data[i].title)
+ .replace(new RegExp('%SUMMARY%', 'g'), data[i].summary);
+
+ html += item;
+
+ }
+
+ results_cache[q] = html;
+
+ $('#ask-related-questions').html(html);
+ }
+ }, 'json');
+
+ return false;
+ }
+
+ $input.keyup(reload_suggestions_box);
+});
\ No newline at end of file
</div>
</script>
<script type="text/javascript">
- $().ready(function(){
+ $(function(){
//set current module button style
$("#nav_ask").attr('className',"on");
$('#editor').TextAreaResizer();
}
});
-
- var $input = $('#id_title');
- var $box = $('#ask-related-questions');
- var template = $('#question-summary-template').html()
-
- function reload_suggestion_box(q) {
- $.post('{% url related_questions %}', {title: q}, function(data) {
- if (data) {
- var html = '';
- for (var i = 0; i < data.length; i++) {
- var item = template.replace(new RegExp('%URL%', 'g'), data[i].url)
- .replace(new RegExp('%SCORE%', 'g'), data[i].score)
- .replace(new RegExp('%TITLE%', 'g'), data[i].title)
- .replace(new RegExp('%SUMMARY%', 'g'), data[i].summary);
-
- html += item;
-
- }
- $('#ask-related-questions').html(html);
- }
- }, 'json');
- }
-
- $input.keyup(function(e) {
- var q = $input.val().trim();
-
- if (e.which == 32 && q.length > 8 && q.split(' ').length > 2) {
- reload_suggestion_box(q);
- }
-
- return true;
- });
-
- $input.change(function() {
- var q = $input.val().trim();
-
- if (q.length > 8) {
- reload_suggestion_box(q);
- }
- });
});
+
+ var related_questions_url = "{% url related_questions %}";
</script>
+ <script src="{% media "/media/js/osqa.ask.js" %}" type="text/javascript"></script>
{% endblock %}
{% block content %}
<!-- question_edit_tips.html -->
{% load i18n %}
-{% block forejs %}
- <script type="text/javascript">
- var currentSideBar = 'div#title_side_bar';
- function changeSideBar(enabled_bar) {
- $(currentSideBar).hide();
- currentSideBar = enabled_bar;
- $(currentSideBar).fadeIn('slow');
-
- }
- $(function () {
- $('div#editor_side_bar').hide();
- $('div#tags_side_bar').hide();
-
- $('input#id_title').focus(function(){changeSideBar('div#title_side_bar')});
- $('textarea#editor').focus(function(){changeSideBar('div#editor_side_bar')});
- $('input#id_tags').focus(function(){changeSideBar('div#tags_side_bar')});
- });
- </script>
-{% endblock %}
<div class="boxC" id="title_side_bar">
<p class="subtitle darkred">{% trans "Title Tips" %}</p>
<div>
+from django.db.models import Q
from forum.models.question import Question, QuestionManager
from forum.modules.decorators import decorate
@decorate(QuestionManager.search, needs_origin=False)
def question_search(self, keywords):
return self.extra(
- tables=['forum_rootnode_doc'],
+ tables = ['forum_rootnode_doc'],
select={
- 'ranking': 'ts_rank_cd(\'{0.1, 0.2, 0.8, 1.0}\'::float4[], "forum_rootnode_doc"."document", plainto_tsquery(\'english\', %s), 32)',
+ 'ranking': """
+ rank_exact_matches(ts_rank_cd('{0.1, 0.2, 0.8, 1.0}'::float4[], "forum_rootnode_doc"."document", plainto_tsquery('english', %s), 32))
+ """,
},
- where=['"forum_rootnode_doc"."node_id" = "forum_node"."id"', '"forum_rootnode_doc"."document" @@ plainto_tsquery(\'english\', %s)'],
+ where=["""
+ "forum_rootnode_doc"."node_id" = "forum_node"."id" AND ("forum_rootnode_doc"."document" @@ plainto_tsquery('english', %s) OR
+ "forum_node"."title" ILIKE '""" + keywords + """%%')
+ """],
params=[keywords],
select_params=[keywords],
order_by=['-ranking']
- )
\ No newline at end of file
+ )
+
drop function build_doc_table();
drop function doc_table_exists();
+CREATE OR REPLACE FUNCTION rank_exact_matches(rank float) RETURNS float AS $$
+begin
+ IF rank = 0 THEN
+ return 1;
+ ELSE
+ return rank;
+ END IF;
+
+end
+$$ LANGUAGE plpgsql;
+
UPDATE forum_noderevision SET id = id WHERE TRUE;
from django.db import connection, transaction\r
import settings\r
\r
-VERSION = 7\r
+VERSION = 8\r
\r
if int(settings.PG_FTSTRIGGERS_VERSION) < VERSION:\r
f = open(os.path.join(os.path.dirname(__file__), 'pg_fts_install.sql'), 'r')\r