LinkedIn提供了一種機制來說明用戶在最近的「x」天內是「n」次搜索條件的一部分。你如何去捕獲和存儲信息。您是否應該迭代搜索結果,並在搜索結果中添加適當的計數器,或者是否存在可以在較低級別(比應用層)更低級別捕獲的非侵入式機制如何查找並存儲用戶參與搜索條件的次數
0
A
回答
1
你可以做這樣的事情(http://pastie.org/1211302):
drop table if exists users;
create table users
(
user_id int unsigned not null auto_increment primary key,
username varbinary(32) unique not null
)
engine=innodb;
insert into users (username) values ('f00'),('bar'),('foobar'),('alpha'),('felix');
drop table if exists user_hits;
create table user_hits
(
hit_id int unsigned not null auto_increment primary key,
hit_date datetime not null,
user_id int unsigned not null,
key hit_date_user_idx(hit_date, user_id)
)
engine=innodb;
drop procedure if exists user_search;
delimiter #
create procedure user_search
(
in p_username varbinary(32)
)
begin
set p_username = trim(replace(p_username, '%',''));
create temporary table matches engine=memory
select * from users where username like concat(p_username,'%');
insert into user_hits (hit_date, user_id) select now(), user_id from matches;
select * from matches order by username;
drop temporary table if exists matches;
end #
delimiter ;
drop procedure if exists user_hits;
delimiter #
create procedure user_hits
(
in p_user_id int unsigned,
in p_day_interval smallint unsigned
)
begin
select
user_id,
hit_date,
count(*) as hits
from
user_hits
where
hit_date between now() - interval p_day_interval day and now() and
user_id = p_user_id
group by
hit_date, user_id;
end #
delimiter ;
-- testing
select * from users;
select * from user_hits;
call user_search('f00');
select * from user_hits;
call user_search('f');
select * from user_hits;
call user_hits(1,7);
1
最簡單的方法是記錄所有搜索,然後統計(使用SQL)特定用戶出現的次數。東西的效果:SELECT COUNT(1) FROM search_log WHERE search_string = 'this-user-name'
這可能是數據然而實時查詢,一個不切實際的量,特別是如果你要計算的搜索,僅僅包括的用戶名(例如,「小狗,小貓,和此用戶名「)。在這種情況下,最直接的方法是在您的user
表中簡單包含一個用於統計搜索的字段。然後,在處理每個搜索時,您可以查找其中的任何用戶名並遞增相應的計數器。
相關問題
- 1. 目錄第一次搜索與查找
- 2. PHP Cookie存儲用戶表單搜索 - 存儲多個搜索
- 3. 如何使用php和Codeigniter存儲搜索條件?
- 4. AUC的網格搜索查找參數
- 5. 用用戶搜索參數生成MySQL JSON_EXTRACT條件
- 6. 在搜索之前修改搜索參數使用查找
- 7. Paginator doens't不存儲搜索參數
- 8. 如何搜索git存儲庫歷史記錄以查找合併錯誤?
- 9. 存儲Rails應用的搜索查詢
- 10. 搜索在數組的值,並存儲它,如果不存在
- 11. 如何找到搜索條件(如果有)將用戶帶到我的網站?
- 12. 搜索數組10次,並計算每次搜索的時間
- 13. Python:如何搜索推文並在數據庫中存儲?
- 14. 使用Sphinx搜索與Azure表存儲
- 15. 將搜索條件存儲在數據庫中
- 16. 保存搜索條從搜索條
- 17. 搜索日期與條件
- 18. LDAP搜索 - 查找與特定用戶的所有組在它
- 19. 你可以一次搜索數據存儲的數據存儲區
- 20. 如何搜索兩個數組並查找是否匹配?
- 21. 存儲/查詢二進制序列並使用掩碼搜索
- 22. 在數據庫中搜索用戶的導航條搜索欄
- 23. 查詢找出所有已定義的觸發器並搜索存儲過程
- 24. 如何設置用戶來控制NetSuite Suitelet中保存的搜索條件SSv2
- 25. 如何查找內存訪問次數
- 26. 如何使用參數搜索數字?
- 27. 如何根據用戶搜索查找城市和國家?
- 28. 存儲搜索條件比發送電子郵件
- 29. 客戶搜索存儲過程
- 30. 使用多個搜索條件查找記錄,包括範圍
不,我不知道發生搜索與用戶標識符(他們可能會像搜索,搜索我的一切某個公司或某個地點的人員,或公司中的某個指定人員)。因此,在這些情況下,雖然 – Sam 2010-10-10 15:03:19
不知道用戶標識符,但您在運行搜索時必須知道哪些用戶符合搜索**(否則您無法顯示它們)。利用這個機會來增加你的'number_of_times_appeared_in_a_search'字段。 – VoteyDisciple 2010-10-10 15:04:38
因此,解決方案將遍歷所有符合特定搜索條件的用戶並更新每個用戶計數器。有沒有辦法在數據庫級本身處理這個問題,而不是在應用程序層,我寧願避免邏輯迭代並更新每個用戶計數器,以滿足搜索條件中的所有用戶。這可能會減慢返回搜索結果所花費的時間。 – Sam 2010-10-10 15:17:24