Пример #1
0
 def test_keyword_search_returns_null(self):
     phrase = "wolf"
     query = (Data.select().join(DataIndex,
                                 on=(Data.number == DataIndex.rowid)).where(
                                     DataIndex.match(phrase)).order_by(
                                         DataIndex.bm25()))
     for result in query:
         print(result.title)
         self.assertIsNone(result.title)
         self.assertEqual(result.title, "")
Пример #2
0
 def test_search_by_keyword(self):
     phrase = "HTTP"
     query = (Data.select().join(DataIndex,
                                 on=(Data.number == DataIndex.rowid)).where(
                                     DataIndex.match(phrase)).order_by(
                                         DataIndex.bm25()))
     expected = "Hypertext Transfer Protocol 2 (HTTP/2)"
     for result in query:
         self.assertTrue(result.title, phrase)
         self.assertEqual(result.title, expected)
         self.assertNotEqual(result.title, "HTTPS")
         self.assertNotEqual(result.title, "DNS")
Пример #3
0
def search_by_keyword():
    """User can enter keywords to search for RFC's - only parses the title.

    Prints all matches with RFC number - user can then enter which RFC number
    to view, if any, or return to Home Page.
    """

    print_by_keyword()
    print("[*] Enter Keyword/s [http/2 hpack]")
    phrase = input(f"{prompt}")
    phrase = sanitize_inputs(phrase)
    query = (Data.select().join(
        DataIndex, on=(Data.number == DataIndex.rowid)).where(
            DataIndex.match(phrase)).order_by(DataIndex.bm25()))
    try:
        for results in query:
            print(
                f"{Color.OKBLUE}Matches:{Color.NOTICE} RFC {results.title[:5]}"
                f"{Color.HEADER}- {results.title[5:]}{Color.END}")
        print()
        search_by_number()
    except OperationalError:
        print("[!!] Database lookup error! [!!]")