Esempio n. 1
0
    def test_search_funcs(self):
        """
        Test functions associated with search.
        """
        query = "Test"
        whoosh_search = search.preform_search(query)

        search.print_info()
Esempio n. 2
0
    def test_search_funcs(self):
        """
        Test functions associated with search.
        """
        query = "Test"
        whoosh_search = search.preform_search(query)

        search.print_info()

        self.assertTrue(
            len(whoosh_search),
            f"Whoosh search returned no results. At least {self.limit} expected"
        )
    def handle(self, *args, **options):

        # Index all un-indexed posts that have a root.
        logger.info(f"Database: {settings.DATABASE_NAME}")
        reset = options['reset']
        remove = options['remove']
        report = options['report']
        index = options['index']

        # Sets the un-indexed flags to false on all posts.
        if reset:
            logger.info(f"Setting indexed field to false on all post.")
            Post.objects.valid_posts(indexed=True).exclude(root=None).update(
                indexed=False)

        # Index a limited number yet unindexed posts
        if index:

            # How many total posts can be indexed
            start_count = Post.objects.valid_posts(indexed=False).exclude(
                root=None).count()
            logger.info(f"Starting with {start_count} unindexed posts")

            posts = Post.objects.valid_posts(indexed=False).exclude(
                root=None)[:index]
            target_count = len(posts)

            logger.info(f"Indexing {target_count} posts")

            # The list of posts to update
            ids = [post.id for post in posts]

            # Add post to search index.
            search.index_posts(posts=posts, overwrite=remove)

            # Set the indexed field to true.
            Post.objects.filter(id__in=ids).update(indexed=True)

            count = Post.objects.valid_posts(indexed=False).exclude(
                root=None).count()
            logger.info(f"Finished with {count} unindexed posts remaining")

        # Report the contents of the index
        if report:
            search.print_info()
    def handle(self, *args, **options):

        # Index all un-indexed posts that have a root.
        logger.debug(f"Database: {settings.DATABASE_NAME}")
        reset = options['reset']
        remove = options['remove']
        report = options['report']
        size = options['size']

        # Sets the un-indexed flags to false on all posts.
        if reset:
            logger.info(f"Setting indexed field to false on all post.")
            Post.objects.valid_posts(indexed=True).exclude(root=None).update(
                indexed=False)

        # Index a limited number yet unindexed posts
        if size:
            build(size=size, remove=remove)

        # Report the contents of the index
        if report:
            search.print_info()