Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
201f821b
Commit
201f821b
authored
Jul 27, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
20ca9109
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
31 deletions
+38
-31
Query.php
lib/Doctrine/Search/Query.php
+38
-31
No files found.
lib/Doctrine/Search/Query.php
View file @
201f821b
...
...
@@ -49,9 +49,9 @@ class Doctrine_Search_Query
*/
public
function
__construct
(
$table
)
{
if
(
is_string
(
$table
))
{
$table
=
Doctrine_Manager
::
table
(
$table
);
}
if
(
is_string
(
$table
))
{
$table
=
Doctrine_Manager
::
table
(
$table
);
}
$this
->
_table
=
$table
;
...
...
@@ -69,7 +69,7 @@ class Doctrine_Search_Query
public
function
search
(
$text
)
{
$text
=
strtolower
(
trim
(
$text
));
$text
=
strtolower
(
trim
(
$text
));
$terms
=
Doctrine_Tokenizer
::
sqlExplode
(
$text
,
' AND '
,
'('
,
')'
);
...
...
@@ -126,7 +126,7 @@ class Doctrine_Search_Query
}
public
function
tokenizeClause
(
$clause
)
{
$clause
=
Doctrine_Tokenizer
::
bracketTrim
(
$clause
);
$clause
=
Doctrine_Tokenizer
::
bracketTrim
(
$clause
);
$terms
=
Doctrine_Tokenizer
::
sqlExplode
(
$clause
,
' '
,
'('
,
')'
);
...
...
@@ -162,46 +162,53 @@ class Doctrine_Search_Query
}
return
$ret
;
}
public
function
parseClause
(
$clause
)
{
$clause
=
Doctrine_Tokenizer
::
bracketTrim
(
$clause
);
$foreignId
=
current
(
array_diff
(
$this
->
_table
->
getColumnNames
(),
array
(
'keyword'
,
'field'
,
'position'
)));
$terms
=
Doctrine_Tokenizer
::
sqlExplode
(
$clause
,
' '
,
'('
,
')'
);
$clause
=
Doctrine_Tokenizer
::
bracketTrim
(
$clause
);
foreach
(
$terms
as
$k
=>
$term
)
{
$terms
[
$k
]
=
$term
;
}
$foreignId
=
current
(
array_diff
(
$this
->
_table
->
getColumnNames
(),
array
(
'keyword'
,
'field'
,
'position'
)));
$terms
=
Doctrine_Tokenizer
::
sqlExplode
(
$clause
,
' AND '
,
'('
,
')'
);
$terms
=
$this
->
tokenizeClause
(
$clause
);
if
(
count
(
$terms
)
>
1
)
{
$ret
=
array
();
foreach
(
$terms
as
$term
)
{
$parsed
=
$this
->
parseClause
(
$term
);
if
(
is_array
(
$term
))
{
$parsed
=
$this
->
parseTerms
(
$term
);
}
else
{
$parsed
=
$this
->
parseClause
(
$term
);
}
$ret
[]
=
$foreignId
.
' IN (SELECT '
.
$foreignId
.
' FROM '
.
$this
->
_table
->
getTableName
()
.
' WHERE '
.
$parsed
.
')'
;
}
$r
=
implode
(
' AND '
,
$ret
);
$r
=
implode
(
' AND '
,
$ret
);
}
else
{
$terms
=
Doctrine_Tokenizer
::
sqlExplode
(
$clause
,
' OR '
,
'('
,
')'
);
$terms
=
(
is_array
(
$terms
[
0
]))
?
$terms
[
0
]
:
array
(
$terms
[
0
]
);
if
(
count
(
$terms
)
>
1
)
{
$ret
=
array
();
foreach
(
$terms
as
$term
)
{
$ret
[]
=
$this
->
parseClause
(
$term
);
return
$this
->
parseTerms
(
$terms
);
}
return
$r
;
}
public
function
parseTerms
(
array
$terms
)
{
if
(
count
(
$terms
)
>
1
)
{
$ret
=
array
();
foreach
(
$terms
as
$term
)
{
$parsed
=
$this
->
parseClause
(
$term
);
if
(
strlen
(
$parsed
)
>
20
)
{
$ret
[]
=
'('
.
$parsed
.
')'
;
}
else
{
$ret
[]
=
$parsed
;
}
$r
=
implode
(
' OR '
,
$ret
);
}
else
{
$ret
=
$this
->
parseTerm
(
$clause
);
return
$ret
[
0
];
}
return
implode
(
' OR '
,
$ret
);
}
else
{
$ret
=
$this
->
parseTerm
(
$terms
[
0
]);
return
$ret
[
0
];
}
return
$r
;
}
public
function
parseAndSeparatedTerms
(
$terms
,
$foreignId
)
{
...
...
@@ -213,7 +220,7 @@ class Doctrine_Search_Query
$ret
[]
=
$foreignId
.
' IN (SELECT '
.
$foreignId
.
' FROM '
.
$this
->
_table
->
getTableName
()
.
' WHERE '
.
$parsed
.
')'
;
}
$r
=
implode
(
' AND '
,
$ret
);
$r
=
implode
(
' AND '
,
$ret
);
}
public
function
parseTerm
(
$term
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment