Example #1
0
    def test_mlt_on_foo_with_filter(self):
        """Verify MLT with the foo field while filtering on tag."""
        # We need to pass min_term_freq and min_doc_freq, because the terms
        # we are using are only once in each document.
        mlt = MLT(1,
                  self.get_s().filter(tag='boring'), ['foo'],
                  min_term_freq=1,
                  min_doc_freq=1)
        eq_(len(mlt), 2)

        mlt = MLT(1,
                  self.get_s().filter(tag='elite'), ['foo'],
                  min_term_freq=1,
                  min_doc_freq=1)
        eq_(len(mlt), 1)

        mlt = MLT(1,
                  self.get_s().filter(tag='awesome'), ['foo'],
                  min_term_freq=1,
                  min_doc_freq=1)
        eq_(len(mlt), 1)

        mlt = MLT(1,
                  self.get_s().filter(tag='gross'), ['foo'],
                  min_term_freq=1,
                  min_doc_freq=1)
        eq_(len(mlt), 0)
Example #2
0
 def test_mlt_on_two_fields(self):
     """Verify MLT on tag and foo fields."""
     mlt = MLT(1,
               self.get_s(), ['tag', 'foo'],
               min_term_freq=1,
               min_doc_freq=1)
     eq_(len(mlt), 5)
Example #3
0
    def test_mlt_on_foo_no_s(self):
        """Verify MLT with the foo field."""
        index = self.get_s().get_indexes()[0]
        doc_type = self.get_s().get_doctypes()[0]
        es = self.get_s().get_es()

        mlt = MLT(1, mlt_fields=['foo'], index=index, doctype=doc_type,
                  es=es, min_term_freq=1, min_doc_freq=1)
        eq_(len(mlt), 4)
def project_detail(projectid):
    global project_s
    global last_url
    
    #getting similar projects
    mlt_s = MLT(projectid, index=IDXPROJ, doctype=DOCTYPE, search_size=3)

    filter_args = {"id": projectid}
    data_s = project_s.filter(**filter_args)
    deli_s = deliv_s.filter(**filter_args)
    code = render_template('project.html', s = data_s[0], d = deli_s[0:50], url = last_url, similar=mlt_s)
    return code
Example #5
0
 def test_mlt_iter(self):
     mlt = MLT(1,
               self.get_s(), ['tag', 'foo'],
               min_term_freq=1,
               min_doc_freq=1)
     eq_(len(list(mlt)), 5)
Example #6
0
 def test_mlt_deprecated_fields(self):
     with self.assertRaises(DeprecationWarning):
         MLT(1, self.get_s(), fields=['tag', 'foo'])
Example #7
0
 def test_mlt_on_tag(self):
     """Verify MLT with the tag field."""
     # We need to pass min_term_freq and min_doc_freq, because the terms
     # we are using are only once in each document.
     mlt = MLT(1, self.get_s(), ['tag'], min_term_freq=1, min_doc_freq=1)
     eq_(len(mlt), 2)
Example #8
0
 def test_bad_mlt(self):
     """Tests S or index and doc_type is specified."""
     self.assertRaises(ValueError, lambda: MLT(1))
     self.assertRaises(ValueError, lambda: MLT(1, index='foo'))
     self.assertRaises(ValueError, lambda: MLT(1, doctype='foo'))
Example #9
0
 def morelikethis(cls, id_, s, fields):
     """morelikethis query."""
     return list(
         MLT(id_, s=s, mlt_fields=fields, min_term_freq=1, min_doc_freq=1))