Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search functionality #79

Merged
merged 40 commits into from
Nov 11, 2013
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b742615
Supports disco#items
Sep 13, 2013
9bfe794
Supports jabber:iq:search
Sep 13, 2013
c18192b
Add basic search classes
Sep 13, 2013
c9ee351
Call process
Sep 13, 2013
f7d5d48
Add template test files
Sep 13, 2013
2f5e07b
Ensure requests come from local users only
Sep 13, 2013
2b92a7b
Test for <query/> child with correct namespace
Sep 13, 2013
a5ebdf5
Add instruction element
Sep 13, 2013
373a3fd
I can haz dataform child :x
Sep 13, 2013
5c959da
Add <title/> child element
Sep 13, 2013
8a63261
Add tests for first form field: FORM_TYPE
Sep 13, 2013
8c2c562
Added tests and code for `content` field
Sep 16, 2013
d2ec9ec
Added test & method for `author` search field
Sep 16, 2013
db0c986
Added test & code for `rpp` form element
Sep 16, 2013
85440e8
Added test & code for `page` form field
Sep 16, 2013
e4ddf7e
Add example search set stanza
Sep 16, 2013
e1670f3
Add `rpp` and `page` to test stanza
Sep 16, 2013
42ed12a
Added test for Set validation and assurance
Sep 16, 2013
0988518
Merge branch 'search' of github.com:surevine/buddycloud-server-java i…
Sep 16, 2013
29d76c3
Added ChannelManager#performSearch and added stub in ChannelManagerIm…
Sep 16, 2013
166fa1c
Added empty result response & test
Sep 16, 2013
d36c7ca
Added in no-result response test and two-item response test
Sep 16, 2013
8a17243
Added test for ignoring of malformed payloads
Sep 16, 2013
78e67d3
Add performSearch() method
Sep 16, 2013
80720e7
Cmd+shift+f
Sep 16, 2013
104fb21
JID not string
Sep 16, 2013
e9d1fd4
Merge branch 'search' of github.com:surevine/buddycloud-server-java i…
Sep 16, 2013
fd9d398
Changed ChannelManger#performSearch to use a JID instead of a string …
Sep 16, 2013
02d06a4
Merge branch 'search' of github.com:surevine/buddycloud-server-java i…
Sep 16, 2013
c1a7f62
First database search test complete
Sep 17, 2013
e764c1d
Unit tests complete for search functionality
Sep 17, 2013
56010ed
Merge branch 'master' of github.com:buddycloud/buddycloud-server-java…
Sep 17, 2013
a420380
Add branch name
Sep 17, 2013
022542f
Check types correctly
Sep 17, 2013
85a5f98
Update search fields
Sep 19, 2013
93e2b97
BareJID not full JID
Sep 19, 2013
a7e5c56
Initialise variable
Sep 19, 2013
1e3db4a
Code formatting
Sep 19, 2013
00323af
Include logger
Sep 19, 2013
a2e1905
Merge branch 'master' of github.com:buddycloud/buddycloud-server-java…
Oct 30, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unit tests complete for search functionality
  • Loading branch information
Lloyd Watkin committed Sep 17, 2013
commit e764c1dd0717851706adc331a361143a35cf3b4e
Original file line number Diff line number Diff line change
@@ -2176,6 +2176,82 @@ public void testOnlySeeSearchResultsFromSubscribedPostsNodes() throws Exception
}
assertEquals(1, counter);
}

@Test
public void testOnlySeeSearchResultsFromRequestedAuthor() throws Exception {
dbTester.loadData("search-test-2");
CloseableIterator<NodeItem> items = store.performSearch(
new JID("user1@server1"), new ArrayList<String>(), new JID("author@server1"), 1, 25
);
int counter = 0;
NodeItem item;
while (items.hasNext()) {
++counter;
item = items.next();
if (1 == counter) {
assertEquals("b1", item.getId());
assertEquals("/users/another-subscribed@server1/posts", item.getNodeId());
} else if (2 == counter) {
assertEquals("a1", item.getId());
assertEquals("/users/subscribed@server1/posts", item.getNodeId());
}
}
assertEquals(2, counter);
}

@Test
public void testOnlySeeSearchResultsWithSpecificContent() throws Exception {
dbTester.loadData("search-test-3");

ArrayList<String> searchTerms = new ArrayList<String>();
searchTerms.add("keyword");
searchTerms.add("post");

CloseableIterator<NodeItem> items = store.performSearch(
new JID("user1@server1"), searchTerms, new JID("author@server1"), 1, 25
);
int counter = 0;
NodeItem item;
while (items.hasNext()) {
++counter;
item = items.next();
if (1 == counter) {
assertEquals("a3", item.getId());
assertEquals("/users/subscribed@server1/posts", item.getNodeId());
} else if (2 == counter) {
assertEquals("a1", item.getId());
assertEquals("/users/subscribed@server1/posts", item.getNodeId());
}
}
assertEquals(2, counter);
}

@Test
public void testOnlySeeSearchResultsWithSpecificContentAndAuthor() throws Exception {
dbTester.loadData("search-test-4");

ArrayList<String> searchTerms = new ArrayList<String>();
searchTerms.add("keyword");
searchTerms.add("post");

CloseableIterator<NodeItem> items = store.performSearch(
new JID("user1@server1"), searchTerms, new JID("author@server1"), 1, 25
);
int counter = 0;
NodeItem item;
while (items.hasNext()) {
++counter;
item = items.next();
if (1 == counter) {
assertEquals("a3", item.getId());
assertEquals("/users/subscribed@server1/posts", item.getNodeId());
} else if (2 == counter) {
assertEquals("a1", item.getId());
assertEquals("/users/subscribed@server1/posts", item.getNodeId());
}
}
assertEquals(2, counter);
}

@Test
public void testBeginTransaction() throws Exception {
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
INSERT INTO "nodes" ("node") VALUES ('/users/subscribed@server1/posts');
INSERT INTO "nodes" ("node") VALUES ('/users/another-subscribed@server1/posts');

INSERT INTO "subscriptions" ("node", "user", "listener", "subscription", "updated")
VALUES ('/users/subscribed@server1/posts', 'user1@server1', 'user1@server1', 'subscribed', current_timestamp - interval '4' second);
INSERT INTO "subscriptions" ("node", "user", "listener", "subscription", "updated")
VALUES ('/users/another-subscribed@server1/posts', 'user1@server1', 'user1@server1', 'subscribed', current_timestamp - interval '3' second);

-- The strange order of insertion of the items is deliberate

-- author@server1
-- not-author@server1
INSERT INTO "items" ("node", "id", "updated", "xml")
VALUES ('/users/subscribed@server1/posts', 'a1', TIMESTAMP '2010-01-08 11:45:12',
'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
<published>2010-01-08T11:45:12Z</published>
<author>
<name>author@server1</name>
<jid xmlns="http://buddycloud.com/atom-elements-0">user2@server1</jid>
</author>
<content type="text">Test 5</content>
<geoloc xmlns="http://jabber.org/protocol/geoloc">
<text>London, England</text>
<locality>London</locality>
<country>England</country>
</geoloc>

<activity:verb>post</activity:verb>
<activity:object>
<activity:object-type>note</activity:object-type>
</activity:object>
</entry>');

INSERT INTO "items" ("node", "id", "updated", "xml")
VALUES ('/users/subscribed@server1/posts', 'a2', TIMESTAMP '2010-01-08 11:45:12',
'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
<published>2010-01-08T11:45:12Z</published>
<author>
<name>not-author@server1</name>
<jid xmlns="http://buddycloud.com/atom-elements-0">user2@server1</jid>
</author>
<content type="text">Test 5</content>
<geoloc xmlns="http://jabber.org/protocol/geoloc">
<text>London, England</text>
<locality>London</locality>
<country>England</country>
</geoloc>

<activity:verb>post</activity:verb>
<activity:object>
<activity:object-type>note</activity:object-type>
</activity:object>
</entry>');

INSERT INTO "items" ("node", "id", "updated", "xml")
VALUES ('/users/another-subscribed@server1/posts', 'b1', TIMESTAMP '2010-01-08 11:45:12',
'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
<published>2010-01-08T11:45:12Z</published>
<author>
<name>author@server1</name>
<jid xmlns="http://buddycloud.com/atom-elements-0">user2@server1</jid>
</author>
<content type="text">Test 5</content>
<geoloc xmlns="http://jabber.org/protocol/geoloc">
<text>London, England</text>
<locality>London</locality>
<country>England</country>
</geoloc>

<activity:verb>post</activity:verb>
<activity:object>
<activity:object-type>note</activity:object-type>
</activity:object>
</entry>');
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
INSERT INTO "nodes" ("node") VALUES ('/users/subscribed@server1/posts');
INSERT INTO "nodes" ("node") VALUES ('/users/pending@server1/posts');

INSERT INTO "subscriptions" ("node", "user", "listener", "subscription", "updated")
VALUES ('/users/subscribed@server1/posts', 'user1@server1', 'user1@server1', 'subscribed', current_timestamp - interval '4' second);
INSERT INTO "subscriptions" ("node", "user", "listener", "subscription", "updated")
VALUES ('/users/pending@server1/posts', 'user1@server1', 'user1@server1', 'pending', current_timestamp - interval '4' second);

-- The strange order of insertion of the items is deliberate

-- author@server1
-- not-author@server1
INSERT INTO "items" ("node", "id", "updated", "xml")
VALUES ('/users/subscribed@server1/posts', 'a1', TIMESTAMP '2010-01-08 11:45:12',
'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
<published>2010-01-08T11:45:12Z</published>
<author>
<name>author@server1</name>
<jid xmlns="http://buddycloud.com/atom-elements-0">user2@server1</jid>
</author>
<content type="text">A post which contains a certain keyword.</content>
<geoloc xmlns="http://jabber.org/protocol/geoloc">
<text>London, England</text>
<locality>London</locality>
<country>England</country>
</geoloc>

<activity:verb>post</activity:verb>
<activity:object>
<activity:object-type>note</activity:object-type>
</activity:object>
</entry>');

INSERT INTO "items" ("node", "id", "updated", "xml")
VALUES ('/users/subscribed@server1/posts', 'a2', TIMESTAMP '2010-01-08 11:45:12',
'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
<published>2010-01-08T11:45:12Z</published>
<author>
<name>author@server1</name>
<jid xmlns="http://buddycloud.com/atom-elements-0">user2@server1</jid>
</author>
<content type="text">Only one keyword in this... item</content>
<geoloc xmlns="http://jabber.org/protocol/geoloc">
<text>London, England</text>
<locality>London</locality>
<country>England</country>
</geoloc>

<activity:verb>post</activity:verb>
<activity:object>
<activity:object-type>note</activity:object-type>
</activity:object>
</entry>');

INSERT INTO "items" ("node", "id", "updated", "xml")
VALUES ('/users/subscribed@server1/posts', 'a3', TIMESTAMP '2010-01-08 11:45:12',
'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
<published>2010-01-08T11:45:12Z</published>
<author>
<name>author@server1</name>
<jid xmlns="http://buddycloud.com/atom-elements-0">user2@server1</jid>
</author>
<content type="text">There is also a keyword in this post.</content>
<geoloc xmlns="http://jabber.org/protocol/geoloc">
<text>London, England</text>
<locality>London</locality>
<country>England</country>
</geoloc>

<activity:verb>post</activity:verb>
<activity:object>
<activity:object-type>note</activity:object-type>
</activity:object>
</entry>');

INSERT INTO "items" ("node", "id", "updated", "xml")
VALUES ('/users/pending@server1/posts', 'a3', TIMESTAMP '2010-01-08 11:45:12',
'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
<published>2010-01-08T11:45:12Z</published>
<author>
<name>author@server1</name>
<jid xmlns="http://buddycloud.com/atom-elements-0">user2@server1</jid>
</author>
<content type="text">There is also a keyword in this post.</content>
<geoloc xmlns="http://jabber.org/protocol/geoloc">
<text>London, England</text>
<locality>London</locality>
<country>England</country>
</geoloc>

<activity:verb>post</activity:verb>
<activity:object>
<activity:object-type>note</activity:object-type>
</activity:object>
</entry>');
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
INSERT INTO "nodes" ("node") VALUES ('/users/subscribed@server1/posts');
INSERT INTO "nodes" ("node") VALUES ('/users/pending@server1/posts');

INSERT INTO "subscriptions" ("node", "user", "listener", "subscription", "updated")
VALUES ('/users/subscribed@server1/posts', 'user1@server1', 'user1@server1', 'subscribed', current_timestamp - interval '4' second);
INSERT INTO "subscriptions" ("node", "user", "listener", "subscription", "updated")
VALUES ('/users/pending@server1/posts', 'user1@server1', 'user1@server1', 'pending', current_timestamp - interval '4' second);

-- The strange order of insertion of the items is deliberate

-- author@server1
-- not-author@server1
INSERT INTO "items" ("node", "id", "updated", "xml")
VALUES ('/users/subscribed@server1/posts', 'a1', TIMESTAMP '2010-01-08 11:45:12',
'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
<published>2010-01-08T11:45:12Z</published>
<author>
<name>author@server1</name>
<jid xmlns="http://buddycloud.com/atom-elements-0">user2@server1</jid>
</author>
<content type="text">A post which contains a certain keyword.</content>
<geoloc xmlns="http://jabber.org/protocol/geoloc">
<text>London, England</text>
<locality>London</locality>
<country>England</country>
</geoloc>

<activity:verb>post</activity:verb>
<activity:object>
<activity:object-type>note</activity:object-type>
</activity:object>
</entry>');

INSERT INTO "items" ("node", "id", "updated", "xml")
VALUES ('/users/subscribed@server1/posts', 'a2', TIMESTAMP '2010-01-08 11:45:12',
'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
<published>2010-01-08T11:45:12Z</published>
<author>
<name>author@server1</name>
<jid xmlns="http://buddycloud.com/atom-elements-0">user2@server1</jid>
</author>
<content type="text">Only one keyword in this... item</content>
<geoloc xmlns="http://jabber.org/protocol/geoloc">
<text>London, England</text>
<locality>London</locality>
<country>England</country>
</geoloc>

<activity:verb>post</activity:verb>
<activity:object>
<activity:object-type>note</activity:object-type>
</activity:object>
</entry>');

INSERT INTO "items" ("node", "id", "updated", "xml")
VALUES ('/users/subscribed@server1/posts', 'a3', TIMESTAMP '2010-01-08 11:45:12',
'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
<published>2010-01-08T11:45:12Z</published>
<author>
<name>author@server1</name>
<jid xmlns="http://buddycloud.com/atom-elements-0">user2@server1</jid>
</author>
<content type="text">There is also a keyword in this post.</content>
<geoloc xmlns="http://jabber.org/protocol/geoloc">
<text>London, England</text>
<locality>London</locality>
<country>England</country>
</geoloc>

<activity:verb>post</activity:verb>
<activity:object>
<activity:object-type>note</activity:object-type>
</activity:object>
</entry>');

INSERT INTO "items" ("node", "id", "updated", "xml")
VALUES ('/users/pending@server1/posts', 'a4', TIMESTAMP '2010-01-08 11:45:12',
'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
<published>2010-01-08T11:45:12Z</published>
<author>
<name>author@server1</name>
<jid xmlns="http://buddycloud.com/atom-elements-0">user2@server1</jid>
</author>
<content type="text">There is also a keyword in this post.</content>
<geoloc xmlns="http://jabber.org/protocol/geoloc">
<text>London, England</text>
<locality>London</locality>
<country>England</country>
</geoloc>

<activity:verb>post</activity:verb>
<activity:object>
<activity:object-type>note</activity:object-type>
</activity:object>
</entry>');


INSERT INTO "items" ("node", "id", "updated", "xml")
VALUES ('/users/subscribed@server1/posts', 'a4', TIMESTAMP '2010-01-08 11:45:12',
'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
<published>2010-01-08T11:45:12Z</published>
<author>
<name>not-author@server1</name>
<jid xmlns="http://buddycloud.com/atom-elements-0">user2@server1</jid>
</author>
<content type="text">A post which contains a certain keyword.</content>
<geoloc xmlns="http://jabber.org/protocol/geoloc">
<text>London, England</text>
<locality>London</locality>
<country>England</country>
</geoloc>

<activity:verb>post</activity:verb>
<activity:object>
<activity:object-type>note</activity:object-type>
</activity:object>
</entry>');

INSERT INTO "items" ("node", "id", "updated", "xml")
VALUES ('/users/subscribed@server1/posts', 'a5', TIMESTAMP '2010-01-08 11:45:12',
'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
<published>2010-01-08T11:45:12Z</published>
<author>
<name>author@server1</name>
<jid xmlns="http://buddycloud.com/atom-elements-0">user2@server1</jid>
</author>
<content type="text">A contains only one keyword.</content>
<geoloc xmlns="http://jabber.org/protocol/geoloc">
<text>London, England</text>
<locality>London</locality>
<country>England</country>
</geoloc>

<activity:verb>post</activity:verb>
<activity:object>
<activity:object-type>note</activity:object-type>
</activity:object>
</entry>');