Пример #1
0
 function testCollectionConstraint()
 {
     parent::$logger->debug('testCollectionConstraint');
     $options = new MLPHP\Options(parent::$client);
     $constraint = new MLPHP\CollectionConstraint("cat", "category/");
     $options->addConstraint($constraint);
     $this->assertXmlStringEqualsXmlString('
         <options xmlns="http://marklogic.com/appservices/search">
           <constraint name="cat">
             <collection prefix="category/"/>
           </constraint>
         </options>
     ', $options->getAsXML());
 }
Пример #2
0
 function testPropertiesConstraint()
 {
     parent::$logger->debug('testPropertiesConstraint');
     $options = new MLPHP\Options(parent::$client);
     $constraint = new MLPHP\PropertiesConstraint("myProperty");
     $options->addConstraint($constraint);
     $this->assertXmlStringEqualsXmlString('
         <options xmlns="http://marklogic.com/appservices/search">
           <constraint name="myProperty">
             <properties />
           </constraint>
         </options>
     ', $options->getAsXML());
 }
 function testElementQueryConstraint()
 {
     parent::$logger->debug('testElementQueryConstraint');
     $options = new MLPHP\Options(parent::$client);
     $constraint = new MLPHP\ElementQueryConstraint("sample-element-constraint", "title", "http://my/namespace");
     $options->addConstraint($constraint);
     $this->assertXmlStringEqualsXmlString('
       <options xmlns="http://marklogic.com/appservices/search">
         <constraint name="sample-element-constraint">
           <element-query name="title" ns="http://my/namespace" />
         </constraint>
       </options>
     ', $options->getAsXML());
 }
Пример #4
0
 function testFieldWordConstraint()
 {
     parent::$logger->debug('testFieldWordConstraint');
     $options = new MLPHP\Options(parent::$client);
     $constraint = new MLPHP\FieldWordConstraint('myName', 'myField');
     $options->addConstraint($constraint);
     $this->assertXmlStringEqualsXmlString('
         <options xmlns="http://marklogic.com/appservices/search">
           <constraint name="myName">
             <word>
               <field name="myField"/>
             </word>
           </constraint>
         </options>
     ', $options->getAsXML());
 }
Пример #5
0
 function testWordConstraint()
 {
     parent::$logger->debug('testWordConstraint');
     $options = new MLPHP\Options(parent::$client);
     $constraint = new MLPHP\WordConstraint('myConstr', 'foo', 'http://example.com/foo', 'barAttr', 'http://example.com/bar');
     $options->addConstraint($constraint);
     $this->assertXmlStringEqualsXmlString('
         <options xmlns="http://marklogic.com/appservices/search">
           <constraint name="myConstr">
               <word>
                  <element ns="http://example.com/foo" name="foo"/>
                  <attribute ns="http://example.com/bar" name="barAttr"/>
               </word>
            </constraint>
         </options>
     ', $options->getAsXML());
 }
Пример #6
0
 function testPathRangeConstraintTest()
 {
     parent::$logger->debug('testPathRangeConstraintTest');
     $options = new MLPHP\Options(parent::$client);
     $constraint = new MLPHP\PathRangeConstraint('myConstraint', 'string', 'false', '/foo/bar/@baz');
     $options->addConstraint($constraint);
     $this->assertXmlStringEqualsXmlString('
         <options xmlns="http://marklogic.com/appservices/search">
           <constraint name="myConstraint">
              <range type="string" facet="false"
               collation="http://marklogic.com/collation/">
                 <path-index>/foo/bar/@baz</path-index>
              </range>
           </constraint>
         </options>
     ', $options->getAsXML());
 }
Пример #7
0
 function testFieldRangeConstraint()
 {
     parent::$logger->debug('testFieldRangeConstraint');
     $options = new MLPHP\Options(parent::$client);
     $constraint = new MLPHP\FieldRangeConstraint('myConstraint', 'xs:string', 'false', 'myField');
     $options->addConstraint($constraint);
     $this->assertXmlStringEqualsXmlString('
         <options xmlns="http://marklogic.com/appservices/search">
           <constraint name="myConstraint">
              <range type="xs:string" facet="false"
               collation="http://marklogic.com/collation/">
                 <field name="myField"/>
              </range>
           </constraint>
         </options>
     ', $options->getAsXML());
 }
Пример #8
0
 function testRangeBucketConstraint()
 {
     parent::$logger->debug('testRangeBucketConstraint');
     $options3 = new MLPHP\Options(parent::$client);
     $constraint3 = new MLPHP\RangeConstraint('myConstr3', 'string', 'true', 'foo');
     $buck1 = new MLPHP\Bucket('low', array('lt' => 10));
     $buck2 = new MLPHP\Bucket('high', array('ge' => 10, 'lt' => 20));
     $constraint3->addBuckets(array($buck1, $buck2));
     $options3->addConstraint($constraint3);
     $this->assertXmlStringEqualsXmlString('
         <options xmlns="http://marklogic.com/appservices/search">
           <constraint name="myConstr3">
            <range type="string" facet="true">
                 <element ns="" name="foo"/>
                 <bucket name="low" lt="10" />
                 <bucket name="high" ge="10" lt="20" />
            </range>
           </constraint>
         </options>
     ', $options3->getAsXML());
 }
Пример #9
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.
*/
use MarkLogic\MLPHP;
require_once 'setup.php';
// Load search options if needed
if (!isset($_SESSION['documents_loaded_usbills']) || !$_SESSION['options_loaded_usbills'] === TRUE) {
    echo '<!-- Loading search options -->' . PHP_EOL;
    $client = new MLPHP\RESTClient($mlphp['host'], $mlphp['port'], $mlphp['path'], $mlphp['version'], $mlphp['username-admin'], $mlphp['password-admin'], $mlphp['auth']);
    // Set up options node
    $options = new MLPHP\Options($client);
    // Range constraint on session
    $session = new MLPHP\RangeConstraint('session', 'xs:int', 'false', 'bill', '', 'session');
    $options->addConstraint($session);
    // Range constraint on type
    $type = new MLPHP\RangeConstraint('type', 'xs:string', 'false', 'bill', '', 'type');
    $options->addConstraint($type);
    // Range constraint on number
    $type = new MLPHP\RangeConstraint('number', 'xs:int', 'false', 'bill', '', 'number');
    $options->addConstraint($type);
    // Range constraint on abbrev
    $type = new MLPHP\RangeConstraint('abbrev', 'xs:string', 'false', 'bill', '', 'abbrev');
    $options->addConstraint($type);
    // Range constraint on introduced
    $type = new MLPHP\RangeConstraint('introduced', 'xs:string', 'false', 'introduced', '', 'date');
    $options->addConstraint($type);
    // Range constraint on status
    $status = new MLPHP\RangeConstraint('status', 'xs:string', 'true', 'status');
    $options->addConstraint($status);
Пример #10
0
if (!empty($redirect)) {
    require_once 'loading.php';
} else {
    //echo "<script>$(window).load(function () { document.write('" . ((!empty($_REQUEST['items'])) ? ' ' . $_REQUEST['items'] : '') . " loaded') });</script>";
}
// Load search options if needed
if (!isset($_SESSION['options_loaded_photomap']) || !$_SESSION['options_loaded_photomap'] === TRUE) {
    echo '<!-- Loading search options -->' . PHP_EOL;
    $client = $mlphp->newClient();
    $client->setUsername($mlphp->config['username-admin']);
    $client->setPassword($mlphp->config['password-admin']);
    // Set up options node
    $options = new MLPHP\Options($client);
    $latConstraint = new MLPHP\RangeConstraint('latitude', 'xs:float', 'false', 'latitude');
    $latConstraint->setFragmentScrope('properties');
    $options->addConstraint($latConstraint);
    $lonConstraint = new MLPHP\RangeConstraint('longitude', 'xs:float', 'false', 'longitude');
    $lonConstraint->setFragmentScrope('properties');
    $options->addConstraint($lonConstraint);
    $hConstraint = new MLPHP\RangeConstraint('height', 'xs:int', 'false', 'height');
    $hConstraint->setFragmentScrope('properties');
    $options->addConstraint($hConstraint);
    $wConstraint = new MLPHP\RangeConstraint('width', 'xs:int', 'false', 'width');
    $wConstraint->setFragmentScrope('properties');
    $options->addConstraint($wConstraint);
    $fConstraint = new MLPHP\RangeConstraint('filename', 'xs:string', 'false', 'filename');
    $fConstraint->setFragmentScrope('properties');
    $options->addConstraint($fConstraint);
    $extracts = new MLPHP\Extracts();
    $extracts->addConstraints(array('latitude', 'longitude', 'height', 'width', 'filename'));
    $options->setExtracts($extracts);
Пример #11
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());
 }
Пример #12
0
 public static function setOptionsXML($client)
 {
     parent::$logger->debug('setOptions');
     $options = new MLPHP\Options($client);
     // Range constraint on session
     $session = new MLPHP\RangeConstraint('session', 'xs:int', 'false', 'bill', '', 'session');
     $options->addConstraint($session);
     // Range constraint on type
     $type = new MLPHP\RangeConstraint('type', 'xs:string', 'false', 'bill', '', 'type');
     $options->addConstraint($type);
     // Range constraint on number
     $type = new MLPHP\RangeConstraint('number', 'xs:int', 'false', 'bill', '', 'number');
     $options->addConstraint($type);
     // Range constraint on abbrev
     $type = new MLPHP\RangeConstraint('abbrev', 'xs:string', 'false', 'bill', '', 'abbrev');
     $options->addConstraint($type);
     // Range constraint on introduced
     $type = new MLPHP\RangeConstraint('introduced', 'xs:string', 'false', 'introduced', '', 'date');
     $options->addConstraint($type);
     // Range constraint on status
     $status = new MLPHP\RangeConstraint('status', 'xs:string', 'true', 'status');
     $options->addConstraint($status);
     // Range constraint on subject
     $keyword = new MLPHP\RangeConstraint('subject', 'xs:string', 'true', 'subject');
     $keyword->setFacetOptions(array('descending', 'frequency-order', 'limit=5'));
     $options->addConstraint($keyword);
     // Range constraint on title
     // $title = new MLPHP\RangeConstraint(
     //     'title', 'xs:string', 'false', 'title'
     // );
     // $options->addConstraint($title);
     // Range constraint on link
     $title = new MLPHP\RangeConstraint('link', 'xs:string', 'false', 'link', '', 'href');
     $options->addConstraint($title);
     // Snippetting prefs
     $transform = new MLPHP\TransformResults('snippet');
     //$pref1 = new MLPHP\PreferredElement('title', '');
     $pref2 = new MLPHP\PreferredElement('summary', '');
     //$transform->addPreferredElements(array($pref1, $pref2));
     $transform->addPreferredElements(array($pref2));
     $options->setTransformResults($transform);
     // Metadata extracts
     $extracts = new MLPHP\Extracts();
     $extracts->addConstraints(array('status', 'subject', 'introduced', 'link', 'session', 'abbrev'));
     $options->setExtracts($extracts);
     $options->setReturnSimilar('true');
     $options->setReturnQuery('true');
     // Term setting
     //$term = new MLPHP\Term("no-results");
     //$options->setTerm($term);
     $options->write('test');
 }
Пример #13
0
$extracts5->addQName('film-title', 'http://marklogic.com/wikipedia');
// Set element namespace
$options5->setExtracts($extracts5);
// Set the extracted metadata in the Options object
$options5->write('options5');
// Write the search options to the database
// Read the options from the database and display
echo "Collection constraint with metadata:\n\n";
echo htmlspecialchars($options5->read('options5'));
echo "\n\n";
// Element-query constraint
$options6 = new MLPHP\Options($client);
// Create an Options object (passing the REST client object)
$eq = new MLPHP\ElementQueryConstraint('title', 'title', 'http://my/namespace');
// Set element namespace
$options6->addConstraint($eq);
// Add the constraint to the Options object
$options6->write('options6');
// Write the search options to the database
// Read the options from the database and display
echo "Element-query constraint:\n\n";
echo htmlspecialchars($options6->read('options6'));
echo "\n\n";
// Various options
$options7 = new MLPHP\Options($client);
// Create an Options object (passing the REST client object)
$options7->setConcurrencyLevel(16);
// Set concurrency level
$options7->setPageLength(20);
// Set page length
$options7->setQualityWeight(0.5);