Search in sources :

Example 6 with SearchServer

use of com.rbmhtechnology.vind.api.SearchServer in project vind by RBMHTechnology.

the class TestServerTest method testSuggestionFiltering.

@Test
public void testSuggestionFiltering() {
    SearchServer server = testSearchServer.getSearchServer();
    SingleValueFieldDescriptor<String> value = new FieldDescriptorBuilder<String>().setSuggest(true).buildTextField("value");
    DocumentFactory documentFactory = new DocumentFactoryBuilder("doc").setUpdatable(true).addField(value).build();
    server.index(documentFactory.createDoc("1").setValue(value, "hello world"));
    server.commit();
    SuggestionResult suggestionResult = server.execute(Search.suggest("he").addField(value), documentFactory);
    SearchResult searchResult = server.execute(Search.fulltext().filter(eq(value, "hello world")), documentFactory);
    Assert.assertEquals(1, searchResult.getNumOfResults());
}
Also used : SuggestionResult(com.rbmhtechnology.vind.api.result.SuggestionResult) SearchServer(com.rbmhtechnology.vind.api.SearchServer) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) Test(org.junit.Test)

Example 7 with SearchServer

use of com.rbmhtechnology.vind.api.SearchServer in project vind by RBMHTechnology.

the class TestServerTest method testSolrUtilDateMultivalueFields.

@Test
public void testSolrUtilDateMultivalueFields() {
    MultiValueFieldDescriptor.UtilDateFieldDescriptor<Date> date = new FieldDescriptorBuilder().buildMultivaluedUtilDateField("date");
    DocumentFactory factory = new DocumentFactoryBuilder("doc").addField(date).build();
    Document document = factory.createDoc("1").setValue(date, new Date());
    SearchServer server = testSearchServer.getSearchServer();
    server.index(document);
    server.commit();
}
Also used : SearchServer(com.rbmhtechnology.vind.api.SearchServer) MultiValueFieldDescriptor(com.rbmhtechnology.vind.model.MultiValueFieldDescriptor) Document(com.rbmhtechnology.vind.api.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Test(org.junit.Test)

Example 8 with SearchServer

use of com.rbmhtechnology.vind.api.SearchServer in project vind by RBMHTechnology.

the class TestServerTest method testTermFacetAccess.

public void testTermFacetAccess() {
    SearchServer server = testSearchServer.getSearchServer();
    MultiValueFieldDescriptor<String> term = new FieldDescriptorBuilder().setFullText(true).setFacet(true).buildMultivaluedTextField("term");
    DocumentFactory factory = new DocumentFactoryBuilder("doc").addField(term).build();
    server.index(factory.createDoc("1").setValue(term, "t1").addValue(term, "t2"));
    server.index(factory.createDoc("2").setValue(term, "t2"));
    server.commit();
    SearchResult result = server.execute(Search.fulltext().facet(term), factory);
    assertEquals(2, result.getFacetResults().getTermFacet(term).getValues().size());
    assertEquals(2, result.getFacetResults().getTermFacet("term", String.class).getValues().size());
    assertEquals(2, result.getFacetResults().getTermFacets().get(term).getValues().size());
}
Also used : SearchServer(com.rbmhtechnology.vind.api.SearchServer) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult)

Example 9 with SearchServer

use of com.rbmhtechnology.vind.api.SearchServer in project vind by RBMHTechnology.

the class TestServerTest method testClearIndex.

// MBDN-432
@Test
public void testClearIndex() {
    // Storing as text_en solr type
    SingleValueFieldDescriptor.TextFieldDescriptor<String> title = new FieldDescriptorBuilder().setFullText(true).setStored(true).buildTextField("title");
    FieldDescriptor<String> entityID = new FieldDescriptorBuilder().buildTextField("entityID");
    SingleValueFieldDescriptor<String> description = new FieldDescriptorBuilder().setLanguage(Language.English).buildTextField("description");
    DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(title).addField(description).addField(entityID).build();
    Document d1 = assets.createDoc("1").setValue(title, "Hello World").setValue(entityID, "123").setValue(description, "This value is not stored");
    Document d2 = assets.createDoc("2").setValue(entityID, "456").setValue(title, "Hello Friends").setValue(description, "This value is also not stored");
    SearchServer server = testSearchServer.getSearchServer();
    server.index(d1);
    server.index(d2);
    server.commit();
    FulltextSearch searchAll = Search.fulltext();
    final SearchResult searchResult = server.execute(searchAll, assets);
    assertEquals("No of results", 2, searchResult.getNumOfResults());
    final Document result = searchResult.getResults().get(0);
    assertThat("Doc-Title", result.getValue(title), Matchers.equalTo("Hello World"));
    server.clearIndex();
    server.commit();
    final SearchResult searchResultClear = server.execute(searchAll, assets);
    assertEquals("No of results", 0, searchResultClear.getNumOfResults());
}
Also used : SearchServer(com.rbmhtechnology.vind.api.SearchServer) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) Document(com.rbmhtechnology.vind.api.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Example 10 with SearchServer

use of com.rbmhtechnology.vind.api.SearchServer in project vind by RBMHTechnology.

the class TestServerTest method timeZoneSearchTest.

// MBDN-441
@Test
public void timeZoneSearchTest() {
    ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
    ZonedDateTime yesterday = ZonedDateTime.now(ZoneId.of("UTC")).minus(1, ChronoUnit.DAYS);
    ZonedDateTime oneHourAgo = ZonedDateTime.now(ZoneId.systemDefault()).minus(1, ChronoUnit.HOURS);
    FieldDescriptor<String> title = new FieldDescriptorBuilder().setFullText(true).buildTextField("title");
    SingleValueFieldDescriptor.DateFieldDescriptor<ZonedDateTime> created = new FieldDescriptorBuilder().setFacet(true).buildDateField("created");
    SingleValueFieldDescriptor.UtilDateFieldDescriptor<Date> modified = new FieldDescriptorBuilder().setFacet(true).buildUtilDateField("modified");
    NumericFieldDescriptor<Long> category = new FieldDescriptorBuilder().setFacet(true).buildMultivaluedNumericField("category", Long.class);
    DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(title).addField(created).addField(category).addField(modified).build();
    Document d1 = assets.createDoc("1").setValue(title, "Hello World").setValue(created, yesterday).setValue(modified, new Date()).setValues(category, Arrays.asList(1L, 2L));
    Document d2 = assets.createDoc("2").setValue(title, "Hello Friends").setValue(created, now).setValue(modified, new Date()).addValue(category, 4L);
    SearchServer server = testSearchServer.getSearchServer();
    server.index(d1);
    server.index(d2);
    server.commit();
    FulltextSearch searchAll = Search.fulltext().filter(before("created", new DateMathExpression().sub(1, HOUR))).timeZone("America/Havana");
    final SearchResult searchResult = server.execute(searchAll, assets);
    assertEquals("No of results", 1, searchResult.getNumOfResults());
    final Document result = searchResult.getResults().get(0);
    assertThat("Doc-Title", result.getValue(title), Matchers.equalTo("Hello World"));
}
Also used : SearchServer(com.rbmhtechnology.vind.api.SearchServer) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) Document(com.rbmhtechnology.vind.api.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ZonedDateTime(java.time.ZonedDateTime) DateMathExpression(com.rbmhtechnology.vind.api.query.datemath.DateMathExpression) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Aggregations

SearchServer (com.rbmhtechnology.vind.api.SearchServer)50 Test (org.junit.Test)46 SolrInputDocument (org.apache.solr.common.SolrInputDocument)31 Document (com.rbmhtechnology.vind.api.Document)30 SearchResult (com.rbmhtechnology.vind.api.result.SearchResult)28 FulltextSearch (com.rbmhtechnology.vind.api.query.FulltextSearch)24 ZonedDateTime (java.time.ZonedDateTime)16 SuggestionResult (com.rbmhtechnology.vind.api.result.SuggestionResult)13 MultiValueFieldDescriptor (com.rbmhtechnology.vind.model.MultiValueFieldDescriptor)12 PageResult (com.rbmhtechnology.vind.api.result.PageResult)11 Interval (com.rbmhtechnology.vind.api.query.facet.Interval)10 DateMathExpression (com.rbmhtechnology.vind.api.query.datemath.DateMathExpression)9 Delete (com.rbmhtechnology.vind.api.query.delete.Delete)9 GetResult (com.rbmhtechnology.vind.api.result.GetResult)9 LatLng (com.rbmhtechnology.vind.model.value.LatLng)8 ByteBuffer (java.nio.ByteBuffer)8 Language (com.rbmhtechnology.vind.annotations.language.Language)7 Search (com.rbmhtechnology.vind.api.query.Search)7 TimeUnit (com.rbmhtechnology.vind.api.query.datemath.DateMathExpression.TimeUnit)7 Facets (com.rbmhtechnology.vind.api.query.facet.Facets)7