changeset 5558:2b7a0e28c4dc

indexers: introduce list of filenames for indexing Before this patch, we cannot search files that without file extension (like Makefile) and dotfiles (like .hgtags). This patch makes it possible to search for these files by introducing a list of filenames for indexing. The list is currently empty.
author Takumi IINO <trot.thunder@gmail.com>
date Sat, 17 Oct 2015 00:12:50 +0900
parents 32cdc6f70f13
children 130f8e170d3c
files kallithea/config/conf.py kallithea/lib/indexers/daemon.py
diffstat 2 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/config/conf.py	Wed Oct 14 20:08:18 2015 +0100
+++ b/kallithea/config/conf.py	Sat Oct 17 00:12:50 2015 +0900
@@ -32,12 +32,14 @@
 # extensions will index it's content
 LANGUAGES_EXTENSIONS_MAP = __get_lem()
 
-#==============================================================================
-# WHOOSH INDEX EXTENSIONS
-#==============================================================================
-# EXTENSIONS WE WANT TO INDEX CONTENT OFF USING WHOOSH
+# Whoosh index targets
+
+# Extensions we want to index content of using whoosh
 INDEX_EXTENSIONS = LANGUAGES_EXTENSIONS_MAP.keys()
 
+# Filenames we want to index content of using whoosh
+INDEX_FILENAMES = []
+
 # list of readme files to search in file tree and display in summary
 # attached weights defines the search  order lower is first
 ALL_READMES = [
--- a/kallithea/lib/indexers/daemon.py	Wed Oct 14 20:08:18 2015 +0100
+++ b/kallithea/lib/indexers/daemon.py	Sat Oct 17 00:12:50 2015 +0900
@@ -41,7 +41,7 @@
 project_path = dn(dn(dn(dn(os.path.realpath(__file__)))))
 sys.path.append(project_path)
 
-from kallithea.config.conf import INDEX_EXTENSIONS
+from kallithea.config.conf import INDEX_EXTENSIONS, INDEX_FILENAMES
 from kallithea.model.scm import ScmModel
 from kallithea.model.db import Repository
 from kallithea.lib.utils2 import safe_unicode, safe_str
@@ -162,6 +162,13 @@
         node = cs.get_node(node_path)
         return node
 
+    def is_indexable_node(self, node):
+        """
+        Just index the content of chosen files, skipping binary files
+        """
+        return (node.extension in INDEX_EXTENSIONS or node.name in INDEX_FILENAMES) and \
+               not node.is_binary
+
     def get_node_mtime(self, node):
         return mktime(node.last_changeset.date.timetuple())
 
@@ -173,8 +180,7 @@
 
         node = self.get_node(repo, path, index_rev)
         indexed = indexed_w_content = 0
-        # we just index the content of chosen files, and skip binary files
-        if node.extension in INDEX_EXTENSIONS and not node.is_binary:
+        if self.is_indexable_node(node):
             u_content = node.content
             if not isinstance(u_content, unicode):
                 log.warning('  >> %s Could not get this content as unicode '