mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	Support comment search
This commit is contained in:
		@@ -5,6 +5,7 @@ from contextlib import contextmanager
 | 
			
		||||
 | 
			
		||||
from dateutil.parser import isoparse
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from documents.models import Comment
 | 
			
		||||
from documents.models import Document
 | 
			
		||||
from whoosh import classify
 | 
			
		||||
from whoosh import highlight
 | 
			
		||||
@@ -49,6 +50,7 @@ def get_schema():
 | 
			
		||||
        path=TEXT(sortable=True),
 | 
			
		||||
        path_id=NUMERIC(),
 | 
			
		||||
        has_path=BOOLEAN(),
 | 
			
		||||
        comments=TEXT(),
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -90,6 +92,7 @@ def open_index_searcher():
 | 
			
		||||
def update_document(writer, doc):
 | 
			
		||||
    tags = ",".join([t.name for t in doc.tags.all()])
 | 
			
		||||
    tags_ids = ",".join([str(t.id) for t in doc.tags.all()])
 | 
			
		||||
    comments = ",".join([str(c.comment) for c in Comment.objects.filter(document=doc)])
 | 
			
		||||
    writer.update_document(
 | 
			
		||||
        id=doc.pk,
 | 
			
		||||
        title=doc.title,
 | 
			
		||||
@@ -110,6 +113,7 @@ def update_document(writer, doc):
 | 
			
		||||
        path=doc.storage_path.name if doc.storage_path else None,
 | 
			
		||||
        path_id=doc.storage_path.id if doc.storage_path else None,
 | 
			
		||||
        has_path=doc.storage_path is not None,
 | 
			
		||||
        comments=comments,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -255,7 +259,7 @@ class DelayedFullTextQuery(DelayedQuery):
 | 
			
		||||
    def _get_query(self):
 | 
			
		||||
        q_str = self.query_params["query"]
 | 
			
		||||
        qp = MultifieldParser(
 | 
			
		||||
            ["content", "title", "correspondent", "tag", "type"],
 | 
			
		||||
            ["content", "title", "correspondent", "tag", "type", "comments"],
 | 
			
		||||
            self.searcher.ixreader.schema,
 | 
			
		||||
        )
 | 
			
		||||
        qp.add_plugin(DateParserPlugin())
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user