def test_boolean():
    """
    We expect a default AND but can do OR.
    """

    store.put(Bag('mybag'))

    tiddlera = Tiddler('a', 'mybag')
    tiddlera.tags = ['one', '@two']
    store.put(tiddlera)

    tiddlerb = Tiddler('b', 'mybag')
    tiddlerb.tags = ['@two', 'three']
    store.put(tiddlerb)

    tiddlerc = Tiddler('c', 'mybag')
    tiddlerc.tags = ['three', 'four']
    store.put(tiddlerc)

    tiddlers = list(search(config, 'tags:one'))
    assert len(tiddlers) == 1

    tiddlers = list(search(config, 'tags:@two'))
    assert len(tiddlers) == 2

    tiddlers = list(search(config, 'tags:one tags:@two'))
    assert len(tiddlers) == 1

    tiddlers = list(search(config, 'tags:one tags:four'))
    assert len(tiddlers) == 0

    tiddlers = list(search(config, 'tags:one OR tags:four'))
    assert len(tiddlers) == 2
Пример #2
0
def test_search_unique():
    bag = Bag('bag1')
    store.put(bag)
    tiddler1 = Tiddler('tiddler1', 'bag1')
    tiddler1.text = 'catsdogshouses'
    store.put(tiddler1)

    tiddler2 = Tiddler('tiddler2', 'bag1')
    tiddler2.text = 'housesdogscats'
    store.put(tiddler2)

    tiddlers = list(search(config, 'catsdogshouses'))
    assert len(tiddlers) == 1
    assert tiddlers[0]['id'] == 'bag1:tiddler1'

    tiddlers = list(search(config, 'housesdogscats'))
    assert len(tiddlers) == 1
    assert tiddlers[0]['id'] == 'bag1:tiddler2'

    store.delete(tiddler1)

    tiddlers = list(search(config, 'catsdogshouses'))
    assert len(tiddlers) == 0

    tiddlers = list(search(config, 'housesdogscats'))
    assert len(tiddlers) == 1
    assert tiddlers[0]['id'] == 'bag1:tiddler2'

    store.delete(tiddler2)

    tiddlers = list(search(config, 'housesdogscats'))
    assert len(tiddlers) == 0
def test_search_unicode():
    bag = Bag(u'\u24b6')
    store.put(bag)
    tiddler1 = Tiddler(u'\u24b6', bag.name)
    tiddler1.text = u'oh \u24b6ss'
    store.put(tiddler1)

    tiddlers = list(search(config, u'\u24b6ss'))
    assert len(tiddlers) == 1
def test_search_quoted_phrase():
    bag = Bag('bag1')
    store.put(bag)
    tiddler1 = Tiddler('tiddler1', 'bag1')
    tiddler1.text = 'There are five monkeys in this house'
    tiddler1.tags = ['oh', 'hai', 'you', 'five chimps']
    store.put(tiddler1)

    tiddlers = list(search(config, '"five monkeys"'))
    assert len(tiddlers) == 1
def test_tags():
    tiddler = Tiddler('hi', 'somewhere')
    tiddler.tags = ['alpha', 'beta', 'gamma']
    store.put(tiddler)

    tiddler = Tiddler('hi2', 'somewhere')
    tiddler.tags = ['alpha', 'gamma']
    store.put(tiddler)

    tiddlers1 = list(search(config, 'tags:beta'))
    tiddlers2 = list(search(config, 'tag:beta'))

    assert tiddlers1 == tiddlers2
    assert len(tiddlers1) == len(tiddlers2)
    assert len(tiddlers1) == 1

    tiddlers1 = list(search(config, 'tags:alpha'))
    tiddlers2 = list(search(config, 'tag:alpha'))

    assert tiddlers1 == tiddlers2
    assert len(tiddlers1) == len(tiddlers2)
    assert len(tiddlers1) == 2

    tiddlers1 = list(search(config, 'tags:beta OR tags:gamma'))
    tiddlers2 = list(search(config, 'tag:beta OR tag:gamma'))
    tiddlers3 = list(search(config, 'tag:beta OR tags:gamma'))

    assert tiddlers1 == tiddlers2
    assert tiddlers2 == tiddlers3
    assert len(tiddlers1) == len(tiddlers2)
    assert len(tiddlers2) == len(tiddlers3)
    assert len(tiddlers1) == 2

    tiddlers1 = list(search(config, 'tags:beta AND tags:gamma'))
    tiddlers2 = list(search(config, 'tag:beta AND tag:gamma'))
    tiddlers3 = list(search(config, 'tag:beta AND tags:gamma'))

    assert tiddlers1 == tiddlers2
    assert tiddlers2 == tiddlers3
    assert len(tiddlers1) == len(tiddlers2)
    assert len(tiddlers2) == len(tiddlers3)
    assert len(tiddlers1) == 1
def test_scoring():
    """title is more imporant than tags is more important than text"""
    store.put(Bag('place'))

    tiddler = Tiddler('test', 'place')
    tiddler.tags = ['apple']
    tiddler.text = 'orange'
    store.put(tiddler)

    tiddler = Tiddler('apple', 'place')
    tiddler.tags = ['orange']
    tiddler.text = 'test'
    store.put(tiddler)

    tiddler = Tiddler('orange', 'place')
    tiddler.tags = ['test']
    tiddler.text = 'apple'
    store.put(tiddler)

    tiddlers = list(search(config, 'test'))

    assert ['test', 'orange', 'apple'] == [tiddler['id'].split(':', 2)[1]
            for tiddler in tiddlers]