Skip to content
This repository

add support for full text search ie. CONTAINS() #50

Closed
lsmith77 opened this Issue July 21, 2012 · 9 comments

3 participants

Lukas Kahwe Smith Crypto Compress Luis Cordova
Lukas Kahwe Smith
Owner

conceptually this should be similar to http://docs.doctrine-project.org/projects/doctrine1/en/latest/en/manual/searching.html
i.e. using an inverted index (http://en.wikipedia.org/wiki/Inverted_index) where we would split all text by word, drop that into a table and use that as a pre filter to reduce the number of rows that are considered for the XPaths.

for specs of CONTAINS() see http://www.day.com/specs/jcr/1.0/8.5.4.5_CONTAINS.html
its ok if initially we do not support the full "lucene" style query syntax

see also http://www.h2database.com/jcr/grammar.html for the grammar of SQL2

also not sure .. but maybe this could help to get started http://code.google.com/p/inverted-index/

Lukas Kahwe Smith
Owner

a quick implementation using equality matching rather than full text searching with normal xpath just to show where the code will need to hook into:

diff --git a/src/Jackalope/Transport/DoctrineDBAL/Query/QOMWalker.php b/src/Jackalope/Transport/DoctrineDBAL/Query/QOMWalker.php
index 7f9ba8c..e34017a 100644
--- a/src/Jackalope/Transport/DoctrineDBAL/Query/QOMWalker.php
+++ b/src/Jackalope/Transport/DoctrineDBAL/Query/QOMWalker.php
@@ -173,6 +173,9 @@ class QOMWalker
         if ($constraint instanceof QOM\SameNodeInterface) {
             return $this->walkSameNodeConstraint($constraint);
         }
+        if ($constraint instanceof QOM\FullTextSearchInterface) {
+            return $this->walkFullTextSearchConstraint($constraint);
+        }

         throw new InvalidQueryException("Constraint " . get_class($constraint) . " not yet supported.");
     }
@@ -187,6 +190,15 @@ class QOMWalker
     }

     /**
+     * @param \PHPCR\Query\QOM\FullTextSearchConstraint $constraint
+     * @return string
+     */
+    public function walkFullTextSearchConstraint(QOM\FullTextSearchInterface $constraint)
+    {
+        return $this->sqlXpathExtractValue($this->getTableAlias($constraint->getSelectorName()), $this->getTableAlias($constraint->getPropertyName())).' = '. $this->conn->quote($constraint->getFullTextSearchExpression());
+    }
+
+    /**
      * @param QOM\PropertyExistenceInterface $constraint
      */
     public function walkPropertyExistanceConstraint(QOM\PropertyExistenceInterface $constraint)
Lukas Kahwe Smith
Owner

just some notes

[16:42] syncNode($uuid, $path, $parent, $type, $isNewNode, $props = array(), $propsData = array())
[16:42] copyNode($srcAbsPath, $dstAbsPath, $srcWorkspace = null)
[16:43] deleteNode($path)
[16:43] deleteProperty($path)
[16:43] in this methods i have to update index... am i missing something?
[16:43] yeah

Luis Cordova

what are those passages references? just curious

Crypto Compress
Collaborator

yes, in QOMWalker the index has to be looked up and in this Client methods the index should be changed

Lukas Kahwe Smith
Owner

@cordoval these are methods in the transport client that get called by jackalope core to write data to the given transports backend. as such these are the places were any additional index needs to be updated.

Lukas Kahwe Smith
Owner

@cryptocompress did you try if it works using the XPath contains() function?

Crypto Compress
Collaborator

sorry, had no time. will do it now.
as described here: http://www.day.com/specs/jcr/1.0/8.5.4.5_CONTAINS.html

Crypto Compress
Collaborator

very early but functional xpath-full-text-search can be found here:
cryptocompress@78af6a4

feedback desired :)

Lukas Kahwe Smith
Owner

ok implemented something ultra simple with LIKE '%foo%' here eaac413

Lukas Kahwe Smith lsmith77 closed this October 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.