Beispiel #1
0
    def test_CustomFiltersScoreQuery(self):
        script1 = "max(1,2)"
        script2 = "min(1,2)"

        filter1 = CustomFiltersScoreQuery.Filter(MatchAllFilter(), 5.0)
        filter2 = CustomFiltersScoreQuery.Filter(NotFilter(MatchAllFilter()),
            script=script1)
        filter3 = CustomFiltersScoreQuery.Filter(NotFilter(MatchAllFilter()),
            script=script2)

        q1 = MatchAllQuery()
        q2 = TermQuery("foo", "bar")

        cfsq1 = CustomFiltersScoreQuery(q1, [filter1, filter2])
        self.assertEquals(cfsq1, CustomFiltersScoreQuery(q1, [filter1, filter2]))
        self.assertEquals(cfsq1.query, q1)
        self.assertEquals(cfsq1.filters, [filter1, filter2])
        self.assertIsNone(cfsq1.score_mode)
        self.assertIsNone(cfsq1.params)
        self.assertIsNone(cfsq1.lang)
        self.assertEquals(cfsq1.serialize(),
                {'custom_filters_score': {
                'query': {'match_all': {}},
                'filters': [
                    filter1.serialize(),
                    filter2.serialize()
                ]}})

        params1 = {"foo": "bar"}
        lang1 = "mvel"
        cfsq2 = CustomFiltersScoreQuery(q2, [filter1, filter2, filter3],
            CustomFiltersScoreQuery.ScoreMode.MAX,
            params1, lang1)
        self.assertEquals(cfsq2,
            CustomFiltersScoreQuery(q2, [filter1, filter2, filter3],
                CustomFiltersScoreQuery.ScoreMode.MAX,
                params1, lang1))
        self.assertEquals(cfsq2.query, q2)
        self.assertEquals(cfsq2.filters, [filter1, filter2, filter3])
        self.assertEquals(cfsq2.score_mode, CustomFiltersScoreQuery.ScoreMode.MAX)
        self.assertEquals(cfsq2.params, params1)
        self.assertEquals(cfsq2.lang, lang1)
        self.assertEquals(cfsq2.serialize(),
                {'custom_filters_score': {
                'query': {'term': {'foo': 'bar'}},
                'filters': [
                    filter1.serialize(),
                    filter2.serialize(),
                    filter3.serialize()
                ],
                'score_mode': 'max',
                'lang': 'mvel',
                'params': {"foo": "bar"}}})
Beispiel #2
0
    def test_CustomFiltersScoreQuery(self):
        script1 = "max(1,2)"
        script2 = "min(1,2)"

        filter1 = FunctionScoreQuery.BoostFunction(boost_factor=5.0,
                                                   filter=MatchAllFilter())

        filter2 = FunctionScoreQuery.ScriptScoreFunction(script=script1,
                                                         filter=NotFilter(
                                                             MatchAllFilter()))
        filter3 = FunctionScoreQuery.ScriptScoreFunction(script=script2,
                                                         filter=NotFilter(
                                                             MatchAllFilter()))

        q1 = MatchAllQuery()
        q2 = TermQuery("foo", "bar")

        cfsq1 = FunctionScoreQuery(query=q1, functions=[filter1, filter2])
        self.assertEqual(
            cfsq1, FunctionScoreQuery(query=q1, functions=[filter1, filter2]))
        self.assertEqual(cfsq1.query, q1)
        self.assertEqual(cfsq1.functions, [filter1, filter2])
        self.assertIsNone(cfsq1.score_mode)
        self.assertIsNone(cfsq1.params)
Beispiel #3
0
    def test_CustomFiltersScoreQuery_Filter(self):
        with self.assertRaises(ValueError) as cm:
            CustomFiltersScoreQuery.Filter(MatchAllFilter())
        self.assertEquals(cm.exception.message,
                          "Exactly one of boost and script must be specified")

        with self.assertRaises(ValueError) as cm:
            CustomFiltersScoreQuery.Filter(MatchAllFilter(), 5.0, "someScript")
        self.assertEquals(cm.exception.message,
                          "Exactly one of boost and script must be specified")

        filter1 = CustomFiltersScoreQuery.Filter(MatchAllFilter(), 5.0)
        self.assertEquals(
            filter1, CustomFiltersScoreQuery.Filter(MatchAllFilter(), 5.0))
        self.assertEquals(filter1.filter_, MatchAllFilter())
        self.assertEquals(filter1.boost, 5.0)
        self.assertIsNone(filter1.script)
        self.assertEquals(filter1.serialize(), {
            'filter': {
                'match_all': {}
            },
            'boost': 5.0
        })

        filter2 = CustomFiltersScoreQuery.Filter(NotFilter(MatchAllFilter()),
                                                 script="hello")
        self.assertEquals(
            filter2,
            CustomFiltersScoreQuery.Filter(NotFilter(MatchAllFilter()),
                                           script="hello"))
        self.assertEquals(filter2.filter_, NotFilter(MatchAllFilter()))
        self.assertEquals(filter2.script, "hello")
        self.assertIsNone(filter2.boost)
        self.assertEquals(filter2.serialize(), {
            'filter': {
                'not': {
                    'filter': {
                        'match_all': {}
                    }
                }
            },
            'script': 'hello'
        })
Beispiel #4
0
  log_context = "upd_type"

  parser = argparse.ArgumentParser(description='met à jour le type des annonces en base')
  parser.add_argument('--test', const=True, action='store_const', help='affiche les annonces mises à jour sans les stocker en base')
  parser.add_argument('--all', const=True, action='store_const', help='met à jour toutes les annonces, et pas seulement celles associées à aucun type')
  parser.add_argument('--term', action='store', help='met à jour uniquement les annonces correspondant au terme précisé')

  args = parser.parse_args()
  
  previous_total = -1
  total = 0
  while previous_total != total:
    # That's odd but it seems we do not update all
    # found pubs... so adding this while loop :(
    previous_total = total
    if args.all: pubs = get_pubs(filter=MatchAllFilter())
    elif args.term: 
      filter=ORFilter([TermFilter(field="description", value=args.term),
                       TermFilter(field="location", value=args.term)])
      pubs = get_pubs(filter=filter)
    else: pubs = get_pubs()

    count = 0
    total = pubs.total
    log('OK', str(total) + ' pubs to update')
    for pub in pubs:
      search_for_types(pub)
      if args.test: show_pub(pub)
      else: insert_to_db(pub)
      count = count + 1
      if count % 20 == 0: