Commit ebcb8eb3 authored by Romain Courteaud's avatar Romain Courteaud

erp5_search_rank_catalog: only check related document with a rank != 0

parent a5611a7a
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, NegatedQuery
portal = context.getPortalObject() portal = context.getPortalObject()
portal_catalog = portal.portal_catalog portal_catalog = portal.portal_catalog
# PR(B) = (1-d) + d x ( PR(A1) / N(A1) + ... + PR(An) / N(An) ) # PR(B) = (1-d) + d x ( PR(A1) / N(A1) + ... + PR(An) / N(An) )
...@@ -16,6 +18,7 @@ rank = 0 ...@@ -16,6 +18,7 @@ rank = 0
# Search all document linking to the context # Search all document linking to the context
for sql_result in portal_catalog( for sql_result in portal_catalog(
select_list=['search_rank'], select_list=['search_rank'],
search_rank=NegatedQuery(SimpleQuery(search_rank=0)),
**{'category.category_uid': context.getUid()} **{'category.category_uid': context.getUid()}
): ):
# In case of acquired category, it is not explicitely defined on the document # In case of acquired category, it is not explicitely defined on the document
......
...@@ -83,13 +83,37 @@ class TestSearchRank(ERP5TypeTestCase): ...@@ -83,13 +83,37 @@ class TestSearchRank(ERP5TypeTestCase):
self.assertIndexedDocumentSearchRankEqual(linked_document_1, '15000') self.assertIndexedDocumentSearchRankEqual(linked_document_1, '15000')
self.assertIndexedDocumentSearchRankEqual(linked_document_2, '15000') self.assertIndexedDocumentSearchRankEqual(linked_document_2, '15000')
# Linked from one document only with no score
linked_document_1.setFooCategoryValue(document)
linked_document_1.Base_zUpdateSearchRank(
uid=linked_document_1.getUid(),
search_rank=0
)
self.tic()
document.Base_updateSearchRank()
self.assertIndexedDocumentSearchRankEqual(document, '15000')
self.assertIndexedDocumentSearchRankEqual(linked_document_1, '0')
self.assertIndexedDocumentSearchRankEqual(linked_document_2, '15000')
# Linked from one document only with a lower score
linked_document_1.setFooCategoryValue(document)
linked_document_1.Base_zUpdateSearchRank(
uid=linked_document_1.getUid(),
search_rank=100
)
self.tic()
document.Base_updateSearchRank()
self.assertIndexedDocumentSearchRankEqual(document, '15085')
self.assertIndexedDocumentSearchRankEqual(linked_document_1, '100')
self.assertIndexedDocumentSearchRankEqual(linked_document_2, '15000')
# Linked from 2 documents (rank is higher than one doc only) # Linked from 2 documents (rank is higher than one doc only)
linked_document_1.setFooCategoryValue(document) linked_document_1.setFooCategoryValue(document)
linked_document_2.setFooCategoryValue(document) linked_document_2.setFooCategoryValue(document)
self.tic() self.tic()
document.Base_updateSearchRank()
linked_document_1.Base_updateSearchRank() linked_document_1.Base_updateSearchRank()
linked_document_2.Base_updateSearchRank() linked_document_2.Base_updateSearchRank()
document.Base_updateSearchRank()
self.assertIndexedDocumentSearchRankEqual(document, '40500') self.assertIndexedDocumentSearchRankEqual(document, '40500')
self.assertIndexedDocumentSearchRankEqual(linked_document_1, '15000') self.assertIndexedDocumentSearchRankEqual(linked_document_1, '15000')
self.assertIndexedDocumentSearchRankEqual(linked_document_2, '15000') self.assertIndexedDocumentSearchRankEqual(linked_document_2, '15000')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment