Beispiel #1
0
 function testSimpleJSON()
 {
     // Load docs that are used in tests that follow
     parent::loadDocsJSON(parent::$client);
     parent::$logger->debug('testSimpleJSON');
     $options = new MLPHP\Options(parent::$client, 'simpleJSON');
     $options->write();
     $search = new MLPHP\Search(parent::$client, 1, 3);
     $results = $search->retrieve('Amodei', array('options' => 'simpleJSON'));
     $this->assertEquals(1, $results->getTotal());
 }
Beispiel #2
0
 function testStructuredQuery()
 {
     parent::$logger->debug('testStructuredQuery');
     $search = new MLPHP\Search(parent::$client, 1, 3);
     $results = $search->retrieve('
         <query xmlns="http://marklogic.com/appservices/search">
             <term-query>
                 <text>MLPHP!!!</text>
             </term-query>
         </query>
     ', array(), true);
     $this->assertEquals(1, $results->getTotal());
     $results = $search->retrieve('
         <query xmlns="http://marklogic.com/appservices/search">
             <term-query>
                 <text>goodbye???</text>
             </term-query>
         </query>
     ', array(), true);
     $this->assertEquals(0, $results->getTotal());
 }
Beispiel #3
0
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// A Simple MLPHP Application
// 1. Complete the installation steps, see: mlphp/README.md
// 2. Tell the app how to talk to MarkLogic.
// Adjust the path below as needed to find the MLPHP project's vendor directory.
require_once __DIR__ . '/../vendor/autoload.php';
use MarkLogic\MLPHP;
// 3. Create a REST client that talks to MarkLogic.
$mlphp = new MLPHP\MLPHP(array('username' => 'rest-writer-user', 'password' => 'writer-pw', 'host' => 'localhost', 'port' => 8077, 'version' => 'v1', 'auth' => 'digest'));
$client = $mlphp->newClient();
// 4. Add a document to the MarkLogic database.
$document = new MLPHP\Document($client);
$document->setContent('<app><description>My first MLPHP app.</description></app>');
$document->write('/myfirstapp.xml');
// 5. Search the MarkLogic database.
$search = new MLPHP\Search($client);
$results = $search->retrieve('MLPHP');
// 6. Display a result.
echo '<html>';
echo '<style>.highlight { background-color: yellow; }</style>';
if ($results->getTotal() > 0) {
    $matches = $results->getResultByIndex(1)->getMatches();
    echo $matches[0]->getContent();
} else {
    echo 'No results found.';
}
echo '</html>';
Beispiel #4
0
                    $image->write($name);
                    // Write image metadata
                    $metadata = new MLPHP\Metadata();
                    $metadata->addProperties(array('latitude' => $image->getLatitude(), 'longitude' => $image->getLongitude(), 'height' => $image->getHeight(), 'width' => $image->getWidth(), 'filename' => $image->getFilename()));
                    $image->writeMetadata($metadata);
                } catch (Exception $e) {
                    echo 'Error: ' . $e->getMessage();
                }
            }
        }
    } catch (Exception $e) {
        echo $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . PHP_EOL;
    }
}
// Get search results
$search = new MLPHP\Search($client);
$params = array('pageLength' => 1000, 'view' => 'all', 'options' => 'photomap', 'format' => 'xml');
$searchResults = $search->retrieve('', $params);
// Write JavaScript data for map.js
echo '<script>' . PHP_EOL;
echo 'var locations = { ' . PHP_EOL;
$lines = array();
foreach ($searchResults->getResults() as $result) {
    $line = '"' . $result->getURI() . '" : { ';
    $props = array();
    foreach ($result->getMetadataKeys() as $key) {
        $props[] = ' "' . $key . '" : "' . $result->getMetadata($key) . '"';
    }
    $line .= implode(',', $props);
    $line .= ' }';
    $lines[] = $line;
Beispiel #5
0
        <option value="112" <?php 
echo $session === '112' ? 'selected' : '';
?>
>112th</option>
    </select>
    <button id="submit" type="submit">Search</button>
</form>
</div>

</div><!-- /header -->

<?php 
if (TRUE) {
    // TODO Change TRUE to not execute search following in some cases?
    // Get search results
    $search = new MLPHP\Search($restClient);
    $start = isset($_REQUEST['start']) ? $_REQUEST['start'] : 1;
    $pageLength = isset($_REQUEST['pageLength']) ? $_REQUEST['pageLength'] : 10;
    $params = array("start" => $start, "pageLength" => $pageLength, "view" => "all", "options" => "usbills", "format" => "xml");
    // Journal filter
    if (empty($_REQUEST['session']) || $_REQUEST['session'] === 'all') {
        $queryModified = $query;
    } else {
        $queryModified = $query . ' session:' . $_REQUEST['session'];
    }
    // Perform search
    $searchResults = $search->retrieve($queryModified, $params);
    //echo '<pre>';
    //print_r($searchResults);
    //echo '</pre>';
    // No results
Beispiel #6
0
See the License for the specific language governing permissions and
limitations under the License.
*/
// Setup
use MarkLogic\MLPHP;
require_once 'setup.php';
$client = $mlphp->newClient();
$client->setUsername($mlphp->config['username-admin']);
$client->setPassword($mlphp->config['password-admin']);
// Load some documents
$doc = new MLPHP\Document($client);
$doc->setContentFile("hamlet.xml")->write("/" . "hamlet.xml");
$doc->setContentFile("macbeth.xml")->write("/" . "macbeth.xml");
$doc->setContentFile("example.json")->write("/" . "example.json");
// Search for a string
$search = new MLPHP\Search($client);
$search->setPageLength(2);
$results = $search->retrieve('donalbain');
echo "Simple text search results:\n\n";
print_r($results);
echo "\n\n\n";
// Search by key-value for an element
$search->setPageLength(1);
$results = $search->retrieveKeyValueElement('PLAYSUBT', '', 'HAMLET');
echo "Key-value (for an element) search results:\n\n";
print_r($results);
echo "\n\n\n";
// Search by key-value for a JSON property
$search->setPageLength(1);
$results = $search->retrieveKeyValue('planet', 'Earth');
echo "Key-value (for JSON) search results:\n\n";
Beispiel #7
0
 function testFieldConstraint()
 {
     parent::$logger->debug('testFieldConstraint');
     $options = new MLPHP\Options(parent::$client, 'testFieldRangeConstraint1');
     $constraint = new MLPHP\FieldRangeConstraint('blah', 'xs:string', 'true', 'field1');
     $options->addConstraint($constraint)->write();
     $search = new MLPHP\Search(parent::$client, 1, 3);
     $results = $search->retrieve('blah:"h 1001"', array('options' => 'testFieldRangeConstraint1'));
     $this->assertEquals(1, $results->getTotal());
     $options = new MLPHP\Options(parent::$client, 'testFieldRangeConstraint2');
     $constraint = new MLPHP\FieldRangeConstraint('foo', 'xs:string', 'false', 'field2');
     $options->addConstraint($constraint)->write();
     $search = new MLPHP\Search(parent::$client, 1, 3);
     $results = $search->retrieve('foo:"110 h 103"', array('options' => 'testFieldRangeConstraint2'));
     $this->assertEquals(1, $results->getTotal());
     $options = new MLPHP\Options(parent::$client, 'testFieldWordConstraint');
     $constraint = new MLPHP\FieldWordConstraint('bar', 'field3');
     $options->addConstraint($constraint)->write();
     $search = new MLPHP\Search(parent::$client, 1, 3);
     $results = $search->retrieve('bar:H.R.', array('options' => 'testFieldWordConstraint'));
     $this->assertEquals(15, $results->getTotal());
 }