Ejemplo n.º 1
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());
 }
Ejemplo n.º 2
0
 $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));
 $options->setTransformResults($transform);
 // Metadata extracts
Ejemplo n.º 3
0
    $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);
    // Write to database
    $optionsid = 'photomap';
    $response = $options->write($optionsid);
    echo '<!--' . $options->read($optionsid) . '-->' . PHP_EOL;
    $_SESSION['options_loaded_photomap'] = TRUE;
} else {
    echo '<!-- Search options already loaded -->' . PHP_EOL;
}
Ejemplo n.º 4
0
 function testFacets()
 {
     parent::$logger->debug('testFacets');
     $options = new MLPHP\Options(parent::$client, 'testFacets');
     $constraint = new MLPHP\RangeConstraint('subject', 'xs:string', 'true', 'subject');
     $constraint->setFacetOptions(array('descending', 'frequency-order', 'limit=5'));
     $options->addConstraint($constraint)->write();
     $search = new MLPHP\Search(parent::$client, 1, 3);
     $results = $search->retrieve('', array('options' => 'testFacets'));
     $facetVals = $results->getFacet('subject')->getFacetValues();
     $this->assertCount(5, $facetVals);
     $this->assertEquals('Commemorations', $facetVals[3]->getName());
     $this->assertGreaterThan($facetVals[4]->getCount(), $facetVals[0]->getCount());
 }
Ejemplo n.º 5
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');
 }
Ejemplo n.º 6
0
Unless required by applicable law or agreed to in writing, software
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.
*/
// Setup
use MarkLogic\MLPHP;
require_once 'setup.php';
$client = $mlphp->newClient();
$client->setUsername($mlphp->config['username-admin']);
$client->setPassword($mlphp->config['password-admin']);
// Range constraint and extracted metadata
$options1 = new MLPHP\Options($client);
// Create an Options object (passing the REST client)
$range = new MLPHP\RangeConstraint('film', 'xs:string', 'true', 'film-title', 'http://marklogic.com/wikipedia', '', '');
// Set attribute namespace
$range->setFragmentScrope('documents');
// Set fragment scope
$options1->addConstraint($range);
// Add the constraint to the Options object
$extracts1 = new MLPHP\Extracts();
// Create an Extracts object (for extracted metadata)
$extracts1->addConstraints('film');
// Add the constraint as extracted metadata
$options1->setExtracts($extracts1);
// Set the extracted metadata in the Options object
$options1->write('options1');
// Write the search options to the database
// Read the options from the database and display
echo "Range constraint and extracted metadata:\n\n";