def test_must_have_facet_a(self):
        document_filter = DocumentFilter()
        documents = document_filter.keep_documents_with_facets(self.generate_data(), [Facet("FacetA", "FacetValueA")])

        self.assertEqual(3, len(documents))
        self.assertTrue("Document1" in documents)
        self.assertTrue("Document2" not in documents)
        self.assertTrue("Document3" in documents)
        self.assertTrue("Document4" in documents)
        self.assertTrue("Document5" not in documents)
    def test_must_not_have_facet_a_or_b(self):
        document_filter = DocumentFilter()
        documents = document_filter.keep_documents_without_facets(self.generate_data(), [Facet("FacetA", "FacetValueA"), Facet("FacetB", "FacetValueB")])

        self.assertEqual(1, len(documents))
        self.assertTrue("Document1" not in documents)
        self.assertTrue("Document2" not in documents)
        self.assertTrue("Document3" not in documents)
        self.assertTrue("Document4" not in documents)
        self.assertTrue("Document5" in documents)
    def test_must_not_have_facet_d(self):
        document_filter = DocumentFilter()
        documents = document_filter.keep_documents_without_facets(self.generate_data(), [Facet("FacetD", "FacetValueD")])

        self.assertEqual(5, len(documents))
        self.assertTrue("Document1" in documents)
        self.assertTrue("Document2" in documents)
        self.assertTrue("Document3" in documents)
        self.assertTrue("Document4" in documents)
        self.assertTrue("Document5" in documents)
    def test_must_not_have_facet_a_and_not_b_comutative(self):
        document_filter = DocumentFilter()
        documents = document_filter.keep_documents_without_facets(self.generate_data(), [Facet("FacetB", "FacetValueB")])
        documents = document_filter.keep_documents_with_facets(documents, [Facet("FacetA", "FacetValueA")])

        self.assertEqual(2, len(documents))
        self.assertTrue("Document1" not in documents)
        self.assertTrue("Document2" not in documents)
        self.assertTrue("Document3" in documents)
        self.assertTrue("Document4" in documents)
        self.assertTrue("Document5" not in documents)
Exemple #5
0
    def test_must_not_have_facet_a(self):
        document_filter = DocumentFilter()
        documents = document_filter.keep_documents_without_facets(
            self.generate_data(), {"FacetA": ["FacetValueA"]})

        self.assertEqual(2, len(documents))
        self.assertTrue("Document1" not in documents)
        self.assertTrue("Document2" in documents)
        self.assertTrue("Document3" not in documents)
        self.assertTrue("Document4" not in documents)
        self.assertTrue("Document5" in documents)
Exemple #6
0
def filter_document_by_facets():
    content = request.get_json()
    documents_to_filter = content['Documents']
    documents = dict((k, facets_by_document[k]) for k in documents_to_filter
                     if k in facets_by_document)

    if content['MustHaveFacets'] is not None:
        must_have_facets = [
            Facet(val['Name'], val['Value'])
            for val in content['MustHaveFacets']
        ]
        documents = DocumentFilter.keep_documents_with_facets(
            documents, must_have_facets)

    if content['MustNotHaveFacets'] is not None:
        must_not_have_facets = [
            Facet(val['Name'], val['Value'])
            for val in content['MustNotHaveFacets']
        ]
        documents = DocumentFilter.keep_documents_without_facets(
            documents, must_not_have_facets)

    return jsonify(list(documents.keys()))