Search Framework: Initial thoughts
This section describes a generalized search framework and a set of hooks for the CRM system. The goal of the framework is to allow additional modules to add fields to the search interface and notify the search framework of the components in database that are used to compose and process the query. The CRM system will be the first test implementation of this facility.
The search framework will need the following information from a module to display the search page
Form Display and Processing
- Input form fields and names (text, textarea, select, radio, date ...)
- Input form data types ( string, email, int, float, text, money, ...)
- Input form validation rules
- Input form help text
- Input form display text
The above is extremely similar to defining extended properties and we will probably reuse the same API
Query creation
The system will have to know the following to formulate a valid query (note that the system is not aware of the relationships between the CRM data model and the external module. We assume that the external module is storing CRM contact ids as foreign keys within its own table)
- Name(s) and Abbreviated Name(s) of the join table(s) needed
- the join condition that links the tables together
- the where clause that filters the search results
- the sort clause if needed
- Field name(s) and data types of the fields(s) in the table(s) that are needed for the sql output
- For each Field Name, the system will need additional information, specifically:
+ Will this value be displayed to the user. YES / TRANSFORM / NO
+ If YES / TRANSFORM, what is the title to be used for the column
+ For TRANSFORM, what is the callback function to be invoked for each record (note the record will be passed as is
to the callback function). The callback function returns a snippet of valid html (either a link or a plain string)
+ The weight of this "property" (where it should occur in the display)
+ The "sort" of this property (true/false)
Example
Consider the below query where we want to find out all the contacts that have donated some amount in a specific time period
For the above case, the framework needs the following information
- text box of type money for AMOUNT
- date widget (m/d/y) of type date for START_DATE
- date widget (m/d/y) of type date for END_DATE
- validation rules that enforce that date is within a certain time frame (in the past)
- name of table: Donate_Transaction, abbreviated name: dt
- name, type, HTML output options of output fields
+ dt.id - int, TRANSFORM (returns a link for detailed donation info using dt.id), Donation Detail
+ dt.amount - money, YES, Donation Amount (alternatively, you could link the amount to Donation Detail using the above id)
+ dt.date - date, YES, Donation Date - join condition: c.id = dt.contact_id
- where clause: dt.amount > AMOUNT and dt.date >= START_DATE and dt.date <= END_DATE
