Beispiel #1
0
 def testSearchWithManyQueries(self):
     """
     L{ObjectAPI.search} can be used to resolve many L{Query}s at once.
     """
     TagAPI(self.user).create([(u'user/tag', u'description')])
     objectID1 = uuid4()
     objectID2 = uuid4()
     index = ObjectIndex(self.client)
     yield index.update({
         objectID1: {
             u'user/tag': 42
         },
         objectID2: {
             u'user/tag': 65
         }
     })
     yield index.commit()
     query1 = parseQuery(u'user/tag = 42')
     query2 = parseQuery(u'user/tag = 65')
     result = self.objects.search([query1, query2])
     result = yield result.get()
     self.assertEqual({
         query1: set([objectID1]),
         query2: set([objectID2])
     }, result)
Beispiel #2
0
 def testBuildIndexWithDirtyIndex(self):
     """
     L{buildIndex} raises a C{RuntimeError} if the Solr index already
     contains documents.
     """
     objectID = uuid4()
     index = ObjectIndex(self.client)
     yield index.update({objectID: {u'test/tag': 42}})
     yield self.client.commit()
     yield self.assertFailure(buildIndex(self.client.url), RuntimeError)
Beispiel #3
0
 def testBuildIndexWithDirtyIndex(self):
     """
     L{buildIndex} raises a C{RuntimeError} if the Solr index already
     contains documents.
     """
     objectID = uuid4()
     index = ObjectIndex(self.client)
     yield index.update({objectID: {u'test/tag': 42}})
     yield self.client.commit()
     yield self.assertFailure(buildIndex(self.client.url), RuntimeError)
Beispiel #4
0
    def testDeleteIndex(self):
        """L{deleteIndex} removes all documents from a Solr index."""
        objectID = uuid4()
        index = ObjectIndex(self.client)
        yield index.update({objectID: {u'test/tag': 42}})
        yield self.client.commit()
        response = yield self.client.search('*:*')
        self.assertEqual([{u'fluiddb/id': str(objectID)}],
                         response.results.docs)

        yield deleteIndex(self.client.url)
        response = yield self.client.search('*:*')
        self.assertEqual([], response.results.docs)
Beispiel #5
0
 def testSearch(self):
     """
     L{SecureObjectAPI.search} resolves the specified L{Query}s if the
     anonymous user has C{Operation.READ_TAG_VALUE} permissions on the
     requested L{Tag.path}s.
     """
     objectID = uuid4()
     index = ObjectIndex(self.client)
     yield index.update({objectID: {u'username/tag': 42}})
     yield self.client.commit()
     query = parseQuery(u'username/tag = 42')
     result = self.objects.search([query])
     result = yield result.get()
     self.assertEqual({query: set([objectID])}, result)
Beispiel #6
0
    def testDeleteIndex(self):
        """L{deleteIndex} removes all documents from a Solr index."""
        objectID = uuid4()
        index = ObjectIndex(self.client)
        yield index.update({objectID: {u'test/tag': 42}})
        yield self.client.commit()
        response = yield self.client.search('*:*')
        self.assertEqual([{
            u'fluiddb/id': str(objectID)
        }], response.results.docs)

        yield deleteIndex(self.client.url)
        response = yield self.client.search('*:*')
        self.assertEqual([], response.results.docs)
Beispiel #7
0
 def testSearchWithQuery(self):
     """
     L{ObjectAPI.search} returns a C{dict} that matches specified L{Query}
     instances to results.
     """
     TagAPI(self.user).create([(u'user/tag', u'description')])
     objectID = uuid4()
     index = ObjectIndex(self.client)
     yield index.update({objectID: {u'user/tag': 42},
                         uuid4(): {u'user/tag': 65}})
     yield index.commit()
     query = parseQuery(u'user/tag = 42')
     result = self.objects.search([query])
     result = yield result.get()
     self.assertEqual({query: set([objectID])}, result)
Beispiel #8
0
 def testSearchWithManyQueries(self):
     """
     L{ObjectAPI.search} can be used to resolve many L{Query}s at once.
     """
     TagAPI(self.user).create([(u'user/tag', u'description')])
     objectID1 = uuid4()
     objectID2 = uuid4()
     index = ObjectIndex(self.client)
     yield index.update({objectID1: {u'user/tag': 42},
                         objectID2: {u'user/tag': 65}})
     yield index.commit()
     query1 = parseQuery(u'user/tag = 42')
     query2 = parseQuery(u'user/tag = 65')
     result = self.objects.search([query1, query2])
     result = yield result.get()
     self.assertEqual({query1: set([objectID1]),
                       query2: set([objectID2])}, result)
Beispiel #9
0
 def testSearchWithoutPermission(self):
     """
     L{SecureObjectAPI.search} raises a L{PermissionDeniedError} if the
     anonymous user doesn't have C{Operation.READ_TAG_VALUE} permissions on
     the requested L{Tag.path}s.
     """
     objectID = uuid4()
     index = ObjectIndex(self.client)
     yield index.update({objectID: {u'username/tag': 42}})
     yield self.client.commit()
     self.permissions.set([(u'username/tag', Operation.READ_TAG_VALUE,
                            Policy.CLOSED, [])])
     query = parseQuery(u'username/tag = 42')
     error = self.assertRaises(PermissionDeniedError, self.objects.search,
                               [query])
     self.assertEqual(u'anon', error.username)
     self.assertEqual([('username/tag', Operation.READ_TAG_VALUE)],
                      error.pathsAndOperations)
Beispiel #10
0
def updateIndex(url, createdAfterTime=datetime.min, stream=sys.stderr):
    """
    Build documents in an L{ObjectIndex} for data in the main store
    that has been updated since the provided C{datetime}.

    @param url: The URL of the Solr index to create documents in.
    @param createdAfterTime: An inclusive C{datetime} offset from which to
        update new tag-values.
    @param stream: The file descriptor to send progress updates to. Defaults to
        C{sys.stderr}.
    @return: A C{Deferred} that will fire with the number of new documents
        that were created in the index.
    """
    client = SolrClient(url)
    index = ObjectIndex(client)
    MAX_DOCUMENTS = 1000

    # setup progress bar
    progressbarWidth = 78
    totalRows = getMainStore().find(TagValue).count()
    documentsPerDash = totalRows / progressbarWidth
    stream.write("[%s]" % (" " * progressbarWidth))
    stream.flush()
    stream.write("\b" * (progressbarWidth + 1))  # return to start of bar

    documents = {}
    documentsProcessed = 0
    result = groupby(_getAllTagValues(createdAfterTime), itemgetter(2))
    for objectID, values in result:
        tagValues = dict((path, value) for path, value, _ in values)
        documents.update({objectID: tagValues})
        if len(documents) >= MAX_DOCUMENTS:
            yield index.update(documents)
            documents = {}
        documentsProcessed += 1
        if documentsProcessed == documentsPerDash:
            stream.write("-")
            stream.flush()
            documentsProcessed = 0
    if documents:
        yield index.update(documents)

    yield client.commit()
Beispiel #11
0
def updateIndex(url, createdAfterTime=datetime.min, stream=sys.stderr):
    """
    Build documents in an L{ObjectIndex} for data in the main store
    that has been updated since the provided C{datetime}.

    @param url: The URL of the Solr index to create documents in.
    @param createdAfterTime: An inclusive C{datetime} offset from which to
        update new tag-values.
    @param stream: The file descriptor to send progress updates to. Defaults to
        C{sys.stderr}.
    @return: A C{Deferred} that will fire with the number of new documents
        that were created in the index.
    """
    client = SolrClient(url)
    index = ObjectIndex(client)
    MAX_DOCUMENTS = 1000

    # setup progress bar
    progressbarWidth = 78
    totalRows = getMainStore().find(TagValue).count()
    documentsPerDash = totalRows / progressbarWidth
    stream.write("[%s]" % (" " * progressbarWidth))
    stream.flush()
    stream.write("\b" * (progressbarWidth + 1))  # return to start of bar

    documents = {}
    documentsProcessed = 0
    result = groupby(_getAllTagValues(createdAfterTime), itemgetter(2))
    for objectID, values in result:
        tagValues = dict((path, value) for path, value, _ in values)
        documents.update({objectID: tagValues})
        if len(documents) >= MAX_DOCUMENTS:
            yield index.update(documents)
            documents = {}
        documentsProcessed += 1
        if documentsProcessed == documentsPerDash:
            stream.write("-")
            stream.flush()
            documentsProcessed = 0
    if documents:
        yield index.update(documents)

    yield client.commit()
Beispiel #12
0
 def testSearchWithQuery(self):
     """
     L{ObjectAPI.search} returns a C{dict} that matches specified L{Query}
     instances to results.
     """
     TagAPI(self.user).create([(u'user/tag', u'description')])
     objectID = uuid4()
     index = ObjectIndex(self.client)
     yield index.update({
         objectID: {
             u'user/tag': 42
         },
         uuid4(): {
             u'user/tag': 65
         }
     })
     yield index.commit()
     query = parseQuery(u'user/tag = 42')
     result = self.objects.search([query])
     result = yield result.get()
     self.assertEqual({query: set([objectID])}, result)