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()); }
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 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()); }
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()); }
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()); }
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()); }
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()); }
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()); }
function testExtracts() { parent::$logger->debug('testExtracts'); $options = new MLPHP\Options(parent::$client); $extracts = new MLPHP\Extracts(); $extracts->addConstraints('foo'); $extracts->addQName('bar', 'http://example.com/bar', 'baz', 'http://example.com/baz'); $options->setExtracts($extracts); $this->assertXmlStringEqualsXmlString(' <options xmlns="http://marklogic.com/appservices/search"> <extract-metadata> <constraint-value ref="foo"/> <qname elem-name="bar" elem-ns="http://example.com/bar" attr-name="baz" attr-ns="http://example.com/baz"/> </extract-metadata> </options> ', $options->getAsXML()); }
function testValuesCollection() { parent::$logger->debug('testValuesCollection'); $options3 = new MLPHP\Options(parent::$client); $values3 = new MLPHP\Values("myValues3"); $values3->setUpCollection(); $values3->setAggregate('sum'); $values3->setValuesOptions(['limit=10']); $options3->addValues($values3); $this->assertXmlStringEqualsXmlString(' <options xmlns="http://marklogic.com/appservices/search"> <values name="myValues3"> <collection/> <aggregate apply="sum"/> <values-option>limit=10</values-option> </values> </options> ', $options3->getAsXML()); }
function testTransformResults() { parent::$logger->debug('testTransformResults'); $options = new MLPHP\Options(parent::$client); $tr = new MLPHP\TransformResults('myTransform'); $pe1 = new MLPHP\PreferredElement('foo', 'http://example.com/foo'); $pe2 = new MLPHP\PreferredElement('bar', 'http://example.com/bar'); $tr->addPreferredElements([$pe1, $pe2]); $options->setTransformResults($tr); $this->assertXmlStringEqualsXmlString(' <options xmlns="http://marklogic.com/appservices/search"> <transform-results apply="myTransform"> <preferred-elements> <element name="foo" ns="http://example.com/foo"/> <element name="bar" ns="http://example.com/bar"/> </preferred-elements> </transform-results> </options> ', $options->getAsXML()); }
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()); }
function testTerm() { parent::$logger->debug('testTerm'); $options = new MLPHP\Options(parent::$client); $term = new MLPHP\Term("all-results"); $term->setTermOptions(['unwildcarded']); $constraint = new MLPHP\PropertiesConstraint("myProperty"); $term->setDefault($constraint); $options->setTerm($term); $this->assertXmlStringEqualsXmlString(' <options xmlns="http://marklogic.com/appservices/search"> <term> <empty apply="all-results"/> <term-option>unwildcarded</term-option> <default> <properties/> </default> </term> </options> ', $options->getAsXML()); }
$options8->setReturnQtext('true'); // Return the qtext $options8->setReturnQuery('false'); // Return the query $options8->setReturnResults('true'); // Return results $options8->setReturnSimilar('false'); // Return similar documents $options8->write('options8'); // Write the search options to the database echo "More options:\n\n"; // Read the options from the database and display echo htmlspecialchars($options8->read('options8')); echo "\n\n"; // Term element $options9 = new MLPHP\Options($client); // Create an Options object (passing the REST client object) $term = new MLPHP\Term('no-results'); // Create an Term object $term->setTermOptions(array('diacritic-insensitive', 'unwildcarded')); // Set a term setting $options9->setTerm($term); // Set the Term object in the options $options9->write('options9'); // Write the search options to the database // Read the options from the database and display echo "Term options:\n\n"; echo htmlspecialchars($options9->read('options9')); echo "\n\n"; // Delete the example options from the database $num = 9;
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()); }
http://www.apache.org/licenses/LICENSE-2.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. */ 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);
*/ use MarkLogic\MLPHP; require_once 'setup.php'; 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);
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'); }