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
569348bd
Commit
569348bd
authored
Jul 26, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
8ee4d75b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
21 deletions
+64
-21
Search.php
lib/Doctrine/Search.php
+1
-1
Query.php
lib/Doctrine/Search/Query.php
+63
-20
No files found.
lib/Doctrine/Search.php
View file @
569348bd
...
...
@@ -132,7 +132,7 @@ class Doctrine_Search
unset
(
$def
[
'sequence'
]);
unset
(
$def
[
'primary'
]);
$col
=
strtolower
(
$name
.
'_'
.
$column
);
$col
=
strtolower
(
Doctrine
::
tableize
(
$name
)
.
'_'
.
$column
);
$def
[
'primary'
]
=
true
;
$fk
[
$col
]
=
$def
;
...
...
lib/Doctrine/Search/Query.php
View file @
569348bd
...
...
@@ -37,24 +37,23 @@ class Doctrine_Search_Query
*/
protected
$_query
;
/**
* @var
array $_aliases an array of searchable component aliases
* @var
Doctrine_Table $_table the index table
*/
protected
$_aliases
=
array
();
protected
$_table
=
array
();
protected
$_sql
=
''
;
/**
* @param
Doctrine_Query $query the base query
* @param
octrine_Table $_table the index table
*/
public
function
__construct
(
$
query
)
public
function
__construct
(
$
table
)
{
if
(
is_string
(
$query
))
{
$this
->
_query
=
new
Doctrine_Query
();
$this
->
_query
->
parseQuery
(
$query
);
}
elseif
(
$query
instanceof
Doctrine_Query
)
{
$this
->
_query
=
$query
;
}
else
{
throw
new
Doctrine_Exception
(
'Constructor argument should be either Doctrine_Query object or a valid DQL query string'
);
}
$this
->
_query
->
getQuery
();
if
(
is_string
(
$table
))
{
$table
=
Doctrine_Manager
::
table
(
$table
);
}
$this
->
_table
=
$table
;
$this
->
_query
=
new
Doctrine_Query
();
}
/**
* getQuery
...
...
@@ -65,13 +64,54 @@ class Doctrine_Search_Query
{
return
$this
->
_query
;
}
public
function
addAlias
(
$alias
)
{
$this
->
_aliases
[]
=
$alias
;
}
public
function
search
(
$text
)
{
$text
=
strtolower
(
trim
(
$text
));
$terms
=
Doctrine_Tokenizer
::
quoteExplode
(
$text
);
$foreignId
=
current
(
array_diff
(
$this
->
_table
->
getColumnNames
(),
array
(
'keyword'
,
'field'
,
'position'
)));
$numTerms
=
count
(
$terms
);
switch
(
$numTerms
)
{
case
0
:
return
false
;
break
;
case
1
:
// only one term found, use fast
$select
=
'SELECT COUNT(keyword) AS relevance, '
.
$foreignId
;
$from
=
'FROM '
.
$this
->
_table
->
getTableName
();
if
(
strpos
(
$terms
[
0
],
"'"
)
===
false
)
{
$where
=
'WHERE keyword = ?'
;
$params
=
array
(
$terms
[
0
]);
}
else
{
$terms
[
0
]
=
trim
(
$terms
[
0
],
"' "
);
$where
=
'WHERE keyword = ?'
;
$terms
=
Doctrine_Tokenizer
::
quoteExplode
(
$terms
[
0
]);
$params
=
$terms
;
foreach
(
$terms
as
$k
=>
$term
)
{
if
(
$k
===
0
)
{
continue
;
}
$where
.=
' AND (position + '
.
$k
.
') = (SELECT position FROM '
.
$this
->
_table
->
getTableName
()
.
' WHERE keyword = ?)'
;
}
}
$groupby
=
'GROUP BY '
.
$foreignId
;
$orderby
=
'ORDER BY relevance'
;
break
;
default
:
}
$this
->
_sql
=
$select
.
' '
.
$from
.
' '
.
$where
.
' '
.
$groupby
.
' '
.
$orderby
;
}
public
function
search2
(
$text
)
{
$text
=
strtolower
(
$text
);
...
...
@@ -107,7 +147,10 @@ class Doctrine_Search_Query
$this
->
_query
->
addWhere
(
implode
(
' OR '
,
$condition
),
$terms
);
}
}
public
function
getSql
()
{
return
$this
->
_sql
;
}
public
function
execute
()
{
$resultSet
=
$this
->
_query
->
execute
();
...
...
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