Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SparqlStoreQueryEngine.php |
— | — | @@ -689,7 +689,13 @@ |
690 | 690 | } |
691 | 691 | |
692 | 692 | //*** Build the condition ***// |
693 | | - $propertyExpElement = SMWExporter::getResourceElement( $diProperty ); |
| 693 | + $typeId = $diProperty->findPropertyTypeID(); |
| 694 | + $diType = SMWDataValueFactory::getDataItemId( $typeId ); |
| 695 | + if ( SMWExporter::hasHelperExpElement( $diType ) ) { |
| 696 | + $propertyExpElement = SMWExporter::getResourceElementForProperty( $diProperty, true ); |
| 697 | + } else { |
| 698 | + $propertyExpElement = SMWExporter::getResourceElementForProperty( $diProperty ); |
| 699 | + } |
694 | 700 | $propertyName = SMWTurtleSerializer::getTurtleNameForExpElement( $propertyExpElement ); |
695 | 701 | if ( $propertyExpElement instanceof SMWExpNsResource ) { |
696 | 702 | $namespaces[$propertyExpElement->getNamespaceId()] = $propertyExpElement->getNamespace(); |
— | — | @@ -725,7 +731,7 @@ |
726 | 732 | $namespaces = array(); |
727 | 733 | $instExpElement = SMWExporter::getSpecialPropertyResource( '_INST' ); |
728 | 734 | foreach( $description->getCategories() as $diWikiPage ) { |
729 | | - $categoryExpElement = SMWExporter::getResourceElement( $diWikiPage ); |
| 735 | + $categoryExpElement = SMWExporter::getResourceElementForWikiPage( $diWikiPage ); |
730 | 736 | $categoryName = SMWTurtleSerializer::getTurtleNameForExpElement( $categoryExpElement ); |
731 | 737 | $namespaces[$categoryExpElement->getNamespaceId()] = $categoryExpElement->getNamespace(); |
732 | 738 | $newcondition = "{ ?$joinVariable " . $instExpElement->getQName() . " $categoryName . }\n"; |
— | — | @@ -787,10 +793,8 @@ |
788 | 794 | case SMW_CMP_LEQ: $comparator = '<='; break; |
789 | 795 | case SMW_CMP_GEQ: $comparator = '>='; break; |
790 | 796 | case SMW_CMP_NEQ: $comparator = '!='; break; |
791 | | -// case SMW_CMP_LIKE: case SMW_CMP_NLKE: |
792 | | -// $comparator = ' LIKE '; |
793 | | -// if ( $description->getComparator() == SMW_CMP_NLKE ) $comparator = " NOT{$comparator}"; |
794 | | -// $value = str_replace( array( '%', '_', '*', '?' ), array( '\%', '\_', '%', '_' ), $value ); |
| 797 | + case SMW_CMP_LIKE: $comparator = 'regex'; break; |
| 798 | + case SMW_CMP_NLKE: $comparator = '!regex'; break; |
795 | 799 | } |
796 | 800 | |
797 | 801 | $namespaces = array(); |
— | — | @@ -798,16 +802,27 @@ |
799 | 803 | $expElement = SMWExporter::getDataItemExpElement( $dataItem ); |
800 | 804 | $result = new SMWSparqlSingletonCondition( $expElement ); |
801 | 805 | $this->addOrderByDataForProperty( $result, $joinVariable, $orderByProperty, $dataItem->getDIType() ); |
802 | | - } else { |
803 | | - $expElement = SMWExporter::getDataItemExpElement( $dataItem ); |
| 806 | + } elseif ( ( $comparator == 'regex' || $comparator == '!regex' ) && ( $dataItem instanceof SMWDIBlob ) ) { |
| 807 | + $pattern = '^' . str_replace( array( '^', '.', '\\', '+', '{', '}', '(', ')', '|', '^', '$', '[', ']', '*', '?' ), |
| 808 | + array( '\^', '\.', '\\\\', '\+', '\{', '\}', '\(', '\)', '\|', '\^', '\$', '\[', '\]', '.*', '.' ), |
| 809 | + $dataItem->getString() ) . '$'; |
| 810 | + $result = new SMWSparqlFilterCondition( "$comparator( ?$joinVariable, \"$pattern\", \"s\")", array() ); |
| 811 | + $this->addOrderByDataForProperty( $result, $joinVariable, $orderByProperty, $dataItem->getDIType() ); |
| 812 | + } elseif ( $comparator != '' ) { |
| 813 | + $expElement = SMWExporter::getDataItemHelperExpElement( $dataItem ); |
| 814 | + if ( $expElement === null ) { |
| 815 | + $expElement = SMWExporter::getDataItemExpElement( $dataItem ); |
| 816 | + } |
804 | 817 | $result = new SMWSparqlFilterCondition( '', array() ); |
805 | 818 | $this->addOrderByData( $result, $joinVariable, $dataItem->getDIType() ); |
806 | | - $orderVariable = $result->orderByVariable; |
| 819 | + $orderByVariable = $result->orderByVariable; |
807 | 820 | $valueName = SMWTurtleSerializer::getTurtleNameForExpElement( $expElement ); |
808 | 821 | if ( $expElement instanceof SMWExpNsResource ) { |
809 | 822 | $result->namespaces[$expElement->getNamespaceId()] = $expElement->getNamespace(); |
810 | 823 | } |
811 | | - $result->filter = "?$orderVariable $comparator $valueName"; |
| 824 | + $result->filter = "?$orderByVariable $comparator $valueName"; |
| 825 | + } else { |
| 826 | + $result = $this->buildTrueCondition( $joinVariable, $orderByProperty ); |
812 | 827 | } |
813 | 828 | |
814 | 829 | return $result; |