Ejemplo n.º 1
0
    def test15_fulltext_result_scoring(self):
        g = Graph('fulltext_scoring', self.env.getConnection())

        # create full-text index over label 'L', attribute 'v'
        g.call_procedure('db.idx.fulltext.createNodeIndex', 'L', 'v')

        # introduce 2 nodes
        g.query("create (:L {v:'hello world hello'})")
        g.query("create (:L {v:'hello world hello world'})")

        # query nodes using fulltext search
        q = """CALL db.idx.fulltext.queryNodes('L', 'hello world') YIELD node, score
               RETURN node.v, score
               ORDER BY score"""
        res = g.query(q)
        actual = res.result_set
        expected = [['hello world hello', 1.5], ['hello world hello world', 2]]
        self.env.assertEqual(expected, actual)
Ejemplo n.º 2
0
import progressbar
from stemming.porter2 import stem

from redisgraph import Node, Edge, Graph

REMOVE_CHARS = [',', '.', ':', '\'', '"', '/', '\n', '\t', '-', ';', '(', ')', '[', ']', '{', '}', '!', '@', '#', '$', '%', '^', '&', '*', '?']

r = redis.Redis(host='localhost', port=6379)
redis_graph = Graph('autocomplete', r)

# Load data.
r.flushall()

# Create Indecies:
redis_graph.query("CREATE INDEX ON :word(value)")
redis_graph.call_procedure("db.idx.fulltext.createNodeIndex", 'word', 'value')

# Populate graph.
with open("./data/words_alpha.txt") as file:
	content = file.read()
	words = content.split()
	words = [w.lower() for w in words if len(w) > 1]
	unique_words = set(words)

	max_node_count = len(unique_words)
	node_count = 0
	with progressbar.ProgressBar(max_value=max_node_count) as bar:
		for word in unique_words:
			n = Node(label='word', properties={'value': word})
			redis_graph.add_node(n)
			node_count += 1