Exemplo n.º 1
0
    def handle_noargs(self, **options):
        """Generates a Solr schema that reflects the indexes."""
        # Cause the default site to load.
        from django.conf import settings
        from haystack import backend, site

        default_operator = getattr(settings, 'HAYSTACK_DEFAULT_OPERATOR',
                                   DEFAULT_OPERATOR)
        content_field_name, fields = backend.SearchBackend().build_schema(
            site.all_searchfields())

        t = loader.get_template('search/configuration/solr.xml')
        c = Context({
            'content_field_name': content_field_name,
            'fields': fields,
            'default_operator': default_operator,
        })
        schema_xml = t.render(c)
        schema_path = os.path.join(SOLR_ROOT, 'solr/conf/schema.xml')
        file = open(schema_path, 'w')
        file.write(schema_xml)
        file.close()
        sys.stderr.write("\n")
        sys.stderr.write("Saved to %s\n" % schema_path)
        sys.stderr.write("You may need to reindex your data\n")
        sys.stderr.write(
            "--------------------------------------------------------------------------------------------\n"
        )
        sys.stderr.write("\n")
Exemplo n.º 2
0
 def handle(self, **options):
     """Clears out the search index completely."""
     # Cause the default site to load.
     site = get_site(options.get('site'))
     self.verbosity = int(options.get('verbosity', 1))
     
     if options.get('interactive', True):
         print
         print "WARNING: This will irreparably remove EVERYTHING from your search index."
         print "Your choices after this are to restore from backups or rebuild via the `rebuild_index` command."
         
         yes_or_no = raw_input("Are you sure you wish to continue? [y/N] ")
         print
         
         if not yes_or_no.lower().startswith('y'):
             print "No action taken."
             sys.exit()
     
     if self.verbosity >= 1:
         print "Removing all documents from your index because you said so."
     
     from haystack import backend
     sb = backend.SearchBackend(site=site)
     sb.clear()
     
     if self.verbosity >= 1:
         print "All documents removed."
Exemplo n.º 3
0
def reset_solr():
    # cause the default site to load
    from haystack import site
    from haystack import backend
    sb = backend.SearchBackend()
    sb.clear()
    call_command('update_index')
Exemplo n.º 4
0
 def setUp(self):
     #clear out existing index without prompting user and ensure that
     #fixtures are indexed
     self.client = Client()
     sb = backend.SearchBackend()
     sb.clear()
     management.call_command('update_index', verbosity=0) #silenced
Exemplo n.º 5
0
    def test_edit_idea_tag(self):
        """
        Check that adding a new idea allows the associated tag to be
        immediately searchable.
        """
        idea = models.Idea(creator=random_user(),
                           title='title',
                           state=models.State.objects.get(name='Active'))
        idea.save()
        results = backend.SearchBackend().search('example_tag')
        self.assertEqual(0, results['hits'])

        req = RequestFactory().post('/', {'tags': 'example_tag'})
        req.user = random_user()
        views.detail(req, str(idea.id))
        results = backend.SearchBackend().search('example_tag')
        self.assertEqual(1, results['hits'])
Exemplo n.º 6
0
 def _test_solr(self):
     print '=== SOLR ==='
     sb = backend.SearchBackend()
     try:
         video = Video.objects.all()[:1].get()
         update_search_index(Video, video.pk)
         sb.conn.commit()
     except (IOError, SolrError), e:
         raise Exception('Solr is unavailable')
Exemplo n.º 7
0
 def test_add_idea_title(self):
     """
     Check that adding a new idea allows title to be immediately
     searchable.
     """
     req = RequestFactory().post('/', {'title': 'example_title'})
     req.user = random_user()
     views.add_idea(req)
     results = backend.SearchBackend().search('example_title')
     self.assertEqual(1, results['hits'])
Exemplo n.º 8
0
    def setUp(self):
        super(QueuedSearchIndexTestCase, self).setUp()

        # Nuke the queue.
        queues.delete_queue(get_queue_name())

        # Nuke the index.
        back = backend.SearchBackend()
        back.clear()

        # Get a queue connection so we can poke at it.
        self.queue = queues.Queue(get_queue_name())
 def build_context(self):
     # Cause the default site to load.
     from haystack import backend, site
     content_field_name, fields = backend.SearchBackend().build_schema(
         site.all_searchfields())
     return Context({
         'content_field_name': content_field_name,
         'fields': fields,
         'default_operator': DEFAULT_OPERATOR,
         'ID': ID,
         'DJANGO_CT': DJANGO_CT,
         'DJANGO_ID': DJANGO_ID,
     })
Exemplo n.º 10
0
def more_like_text(text, klass):
    """
    Return more entries like the provided chunk of text. We have to jump
    through some hoops to get this working as the haystack API does not
    account for this case. In particular, this is a solr-specific hack.
    """
    back = backend.SearchBackend()
    if hasattr(back, 'conn'):
        params = {'fl': '*,score', 'stream.body': text}
        solr_results = back.conn.more_like_this('',
                back.site.get_index(klass).get_content_field(), **params)
        return back._process_results(solr_results)['results']
    else:
        return []
Exemplo n.º 11
0
    def setUp(self):
        super(ProcessSearchQueueTestCase, self).setUp()

        # Nuke the queue.
        queues.delete_queue(get_queue_name())

        # Nuke the index.
        back = backend.SearchBackend()
        back.clear()

        # Get a queue connection so we can poke at it.
        self.queue = queues.Queue(get_queue_name())

        # Clear out and capture log messages.
        AssertableHandler.stowed_messages = []

        self.psqc = ProcessSearchQueueCommand()
Exemplo n.º 12
0
    def test_similar(self, render):
        """
        List of similar ideas should make sense.
        """
        class Mock():
            pass

        with patch('idea.views.more_like_text') as mlt:
            backend.SearchBackend().clear()
            user = random_user()
            state = models.State.objects.get(name='Active')
            similar1 = models.Idea(creator=user,
                                   title='airplanes',
                                   state=state,
                                   text="Title is enough said.")
            similar1.save()
            similar2 = models.Idea(creator=user,
                                   title='exexex',
                                   state=state,
                                   text="I, too, love submarines.")
            similar2.save()

            models.Idea(creator=user,
                        title='AAAAAA',
                        state=state,
                        text='BBBBBB').save()

            m1, m2 = Mock(), Mock()
            m1.object = similar1
            m2.object = similar2
            mlt.return_value = [m1, m2]

            views.add_idea(
                mock_req('/?idea_title=' + 'Airplanes%20and%20submarines'))
            context = render.call_args[0][2]
            self.assertTrue('similar' in context)
            self.assertEqual(2, len(context['similar']))
            self.assertEqual(set(context['similar']), set([similar1,
                                                           similar2]))
 def handle_noargs(self, **options):
     """Generates a Solr schema that reflects the indexes."""
     # Cause the default site to load.
     from django.conf import settings
     from haystack import backend, site
     
     content_field_name, fields = backend.SearchBackend().build_schema(site.all_searchfields())
     
     t = loader.get_template('search_configuration/solr.xml')
     c = Context({
         'content_field_name': content_field_name,
         'fields': fields,
         'default_operator': DEFAULT_OPERATOR,
     })
     schema_xml = t.render(c)
     sys.stderr.write("\n")
     sys.stderr.write("\n")
     sys.stderr.write("\n")
     sys.stderr.write("Save the following output to 'schema.xml' and place it in your Solr configuration directory.\n")
     sys.stderr.write("--------------------------------------------------------------------------------------------\n")
     sys.stderr.write("\n")
     print schema_xml
    def handle_noargs(self, **options):
        """Provides feedback about the current Haystack setup."""
        # Cause the default site to load.
        from haystack import site

        print
        print "WARNING: This will irreparably remove EVERYTHING from your search index."
        print "Your choices after this are to restore from backups or rebuild via the `reindex` command."

        yes_or_no = raw_input("Are you sure you wish to continue? [y/N] ")
        print

        if not yes_or_no.lower().startswith('y'):
            print "No action taken."
            sys.exit()

        print "Removing all documents from your index because you said so."

        from haystack import backend
        sb = backend.SearchBackend()
        sb.clear()

        print "All documents removed."
Exemplo n.º 15
0
 def setUp(self):
     backend.SearchBackend().clear()
Exemplo n.º 16
0
 def __init__( self ):
     self.backend = backend.SearchBackend()