def testSearchId(self): index = Index(fs, testIndexPath) index.create() content = "This is just some test content." index.indexContent(content, id="testId") searchResults = index.searchId("testId") self.assertTrue(searchResults is not None) self.assertEqual(searchResults.value.get("id"), "testId") searchResults.close()
def testSearchMeta(self): index = Index(fs, testIndexPath) index.create() content = "This is just some test content." index.indexContent(content, id="testId", metaItems={"meta": "one"}) searchResults = index.searchMeta("meta", "one") #print searchResults self.assertTrue(searchResults is not None) self.assertTrue(searchResults["testId"].get("id"), "testId") searchResults.close()
def testKeywords(self): index = Index(fs, testIndexPath) index.create() content = "This is just some test content." index.indexContent(content, id="testId", other="one two") searchResults = index.searchContents("other:one") self.assertEqual(searchResults.keys(), ["testId"]) searchResults.close() searchResults = index.searchContents("other:two") self.assertEqual(searchResults.keys(), ["testId"]) searchResults.close()
def testDelete(self): index = Index(fs, testIndexPath) index.create() content = "This is just some test content." index.indexContent(content, id="testId") searchResults = index.searchId("testId") self.assertTrue(searchResults is not None) searchResults.close() index.deleteIndex("testId") searchResults = index.searchId("testId") self.assertEqual(searchResults.keys(), []) searchResults.close() searchResults = index.searchContents("content") self.assertEqual(searchResults.keys(), []) searchResults.close()
def testSearchContent(self): index = Index(fs, testIndexPath) index.create() content = "This is just some test one content." index.indexContent(content, id="testId1", title="OneTitle") content = "This is just some test two content." index.indexContent(content, id="testId2", title="Two Title") searchResults = index.searchContents("content") self.assertEqual(len(searchResults), 2) self.assertEqual(searchResults["testId1"].get("id"), "testId1") self.assertEqual(searchResults["testId1"].get("title"), "OneTitle") searchResults.close() searchResults = index.searchContents("notInContent") self.assertEqual(len(searchResults), 0) searchResults.close()
def testIndexContent3(self): index = Index(fs, testIndexPath) index.create() content = "" meta = {"ids": ["1234"], "1234": ["tag1 tag2", "tag3"]} index.indexContent(content, id="one", metaItems=meta) searchResults = index.search("ids:1234") #print "found %s" % len(searchResults) for doc in searchResults.itervalues(): #print doc.get("1234") #print "x='%s'" % doc.get("x") #print dir(doc) for field in doc.getFields(): #print field.name(), field.stringValue() pass searchResults.close()
def testIndexContent2(self): index = Index(fs, testIndexPath) index.create() content = "" meta = { "one": "oNe", "tags": ["one", "tWo", "teST", "this"], "path": "/one/TWo/three" } index.indexContent(content, id="testId", metaItems=meta, comments="Comments One") meta = { "one": "ONE", "tags": ["one", "twO", "Test", "this"], "path": "/one/TWo/four" } index.indexContent(content, id="testId2", metaItems=meta, comments="Comments Two") # NOTE: there are NO wild cards in keywordQueries and are case-sensitive (not the storing analyzer # may have already lowerCased the content # also pathQueryStr is case-sensitive and may only contain a optional trailing '*' searchResults = index.search(queryStr="tags:tEst ", keywordQueryStr=None, pathQueryStr=None) for id, doc in searchResults.iteritems(): #print "'%s', '%s', '%s'" % (doc.get("comments"), doc.get("one"), doc.get("list")) pass self.assertEqual(len(searchResults), 2) searchResults.close() searchResults = index.search(queryStr=None, keywordQueryStr=None, pathQueryStr="/one/TWo/*") for id, doc in searchResults.iteritems(): #print "'%s', '%s', '%s'" % (doc.get("comments"), doc.get("one"), doc.get("list")) pass self.assertEqual(len(searchResults), 2) searchResults.close()
def testIndexContent(self): index = Index(fs, testIndexPath) index.create() content = "This is just some test content." index.indexContent(content, id="testId") searchResults = index.searchContents("content") self.assertEqual(len(searchResults), 1) searchResults.close() searchResults = index.searchContents("notInContent") self.assertEqual(len(searchResults), 0) searchResults.close() index = Index(fs, testIndexPath) index.indexContent(content, id="testId2") searchResults = index.searchContents("content") expected = ["testId", "testId2"] ids = searchResults.keys() ids.sort() expected.sort() self.assertEqual(ids, expected) searchResults.close()