This may not be relevant to your issue, but maybe to your solution. I
will try to explain how I did my search functionality.

In my application, the user will search for a specific object
(Article, Author, Blog, etc.), not a combination of these.

The search form provides the following entries:
Words [text] - one or more words

Word criteria [radiogroup] - :
1) must contain all words.
2) must contain at least one word.
3) must contain exact phrase.

Search criteria [checkbox] - :
1) In title (default).
2) In summary.
3) In body.

Category(ies) [checkbox] - all categories.

When the user submits the search, the first thing I do, is to save the
search parameters in the database (Enquiry model), so as to get an ID.

The search parameters are then passed on to the responsible model
(Article, Author, Blog, etc), which then performs the actual search.
The resulting rows (ids) are passed back to the Enquiry model, which
saves the result (creates relationships between Enquiry model and
responsible model).

I then uses the ID to paginate the result, when presenting it to the
user.

Building the search query:
1) I split into single words from the Words entry.
2) Based on the Word criteria, I prepare the respective AND, OR, or
phrase condition(s) for all possible Search criteria. That is one for
Title, one for Summary and one for Body.
3) Based on the Search criteria, I include the respective conditions
for Title, Summary and/or Body.

The resulting find conditions looks like this (Words equal "a b c",
Word criteria "must contain all words", Search critera "In title, In
summary, In body":
[code]
Array
(
   [OR] => Array
      (
         [0] => Array
            (
               [AND] => Array
                  (
                     [0] => Array
                        (
                           [LOWER(Article.title) LIKE] => %a%
                        )
                     [1] => Array
                        (
                           [LOWER(Article.title) LIKE] => %b%
                        )
                     [2] => Array
                        (
                           [LOWER(Article.title) LIKE] => %c%
                        )
                  )
            )
         [1] => Array
            (
               [AND] => Array
                  (
                     [0] => Array
                        (
                           [LOWER(Article.summary) LIKE] => %a%
                        )
                     [1] => Array
                        (
                           [LOWER(Article.summary) LIKE] => %b%
                        )
                     [2] => Array
                        (
                           [LOWER(Article.summary) LIKE] => %c%
                        )
                  )
            )
         [2] => Array
            (
               [AND] => Array
                  (
                     [0] => Array
                        (
                           [LOWER(Article.content) LIKE] => %a%
                        )
                     [1] => Array
                        (
                           [LOWER(Article.content) LIKE] => %b%
                        )
                     [2] => Array
                        (
                           [LOWER(Article.content) LIKE] => %c%
                        )
                   )
             )
      )
   [Article.state] => 2
)
[/code]

If you have questions to the above, or just curious about other
things, feel free to ask :) Hope you will get your search up and
running!
Enjoy,
   John


[snip]

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to