-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample.pl
executable file
·121 lines (97 loc) · 4.06 KB
/
example.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/opt/local/bin/perl
#
# This file is part of OpenSearchServer PERL Client.
#
# Copyright (C) 2013-2017 Emmanuel Keller / Jaeksoft
#
# http://www.opensearchserver.com
#
# OpenSearchServer PERL Client is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenSearchServer PERL Client is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with OpenSearchServer PERL Client. If not, see <http://www.gnu.org/licenses/>.
#
use Data::Dumper;
use OpenSearchServer;
# The URL to your OpenSearchServer instance: http://localhost:8080
$oss_url = $ENV{'OSS_URL'};
# The (optional) login used to connect to the API
$oss_login = $ENV{'OSS_LOGIN'};
# The (optional) api key used to connect to the API
$oss_key = $ENV{'OSS_KEY'};
# The name of the index
$oss_index = $ENV{'OSS_INDEX'};
# The name of the query template
$template = 'search';
# The searched keywords
$keywords = 'test';
# The position of the first result
$start = 0;
# The number of rows
$rows = 10;
# The Lang of the keywords
$lang = 'FRENCH';
# An array defining the sort order (optional)
@sort = ('-score', '+lang');
# An array of sub query filters
@filter = ('author:bruno');
print 'CALL: '.$oss_url."\n";
my $result = search_pattern($oss_url, $oss_login, $oss_key, $oss_index, $template, $keywords, $start, $rows, $lang, \@sort, \@filter);
#Get the number of document found
my $found = search_num_found($result);
my $highest_score = search_max_score($result);
print 'NUM FOUND: '.$found.' - Highest score: '.$highest_score."\n";
#Get the number of documents returned
my $doc_returned = search_documents_returned($result);
print 'DOCUMENTS RETURNED: '.$doc_returned."\n";
# Loop over the returned document
for (my $i = 0; $i < $doc_returned; $i++) {
# Get the field
my $id = search_document_field($result, $i, 'product_id');
my $name = search_document_snippet($result, $i, 'name');
my $score = search_document_score($result, $i);
my $parution_dates = search_document_field_values($result, $i, 'parution_date');
my $wrong_field = search_document_field($result, $i, 'wrong_field');
print 'Document #'.$i.' - id: '.$id.' - name: '.$name.' - Date: '.$parution_dates->[0].' - score: '.$score."\n";
}
# Retrieve the number of terms for a facet
my $facet_number = search_get_facet_number($result, 'parution_date_year');
print 'FACET NUMBER for parution_date_year: '.$facet_number."\n";
# Loop over the facet to retrieve the terms and count
for (my $i = 0; $i < $facet_number; $i++) {
my $term = search_get_facet_term($result, 'parution_date_year', $i);
my $count = search_get_facet_count($result, 'parution_date_year', $i);
print 'Facet '.$term.': '.$count."\n";
}
# Test autocompletion
print 'TEST AUTOCOMPLETION'."\n";
my $terms = autocompletion_query($oss_url, $oss_login, $oss_key, $oss_index, 'autocompletion', 'a', 5);
for my $term (@$terms) {
print $term."\n";
}
# Test moreLikeThis
print 'TEST MORE LIKE THIS'."\n";
$result = morelikethis_liketext($oss_url, $oss_login, $oss_key, $oss_index, 'morelikethis','test', 0, 5);
#Get the number of documents returned
$doc_returned = search_documents_returned($result);
print 'DOCUMENTS RETURNED: '.$doc_returned."\n";
# Loop over the returned document
for (my $i = 0; $i < $doc_returned; $i++) {
# Get the field
my $id = search_document_field($result, $i, 'product_id');
my $title = search_document_field($result, $i, 'title');
my $score = search_document_score($result, $i);
print 'Document #'.$i.' - id: '.$id.' - title: '.$title.' - score: '.$score."\n";
}
# Test spellCheckQuery
print 'TEST SPELLCHECK QUERY'."\n";
$result = spellcheck_query($oss_url, $oss_login, $oss_key, $oss_index, 'spellcheck', 'tweest', 'fr');
print Dumper($result);