Discussion:
Solr client on VMS
Add Reply
Arne Vajhøj
2024-12-07 00:49:44 UTC
Reply
Permalink
I have been looking a bit at Solr recently. For those that don't
know Solr, then it is a text search engine - or more accurate it
is a web frontend for the Lucene text search engine. Both
Solr and Lucene are Apache projects (open source).

Solr is basically exposing a web API, so anything that can do
HTTP POST can use Solr. But clients encapsulating the HTTP
stuff does exist for many languages. On VMS then both JVM languages
and Python should be able to use a standard client.

But there are also the traditional languages. Maybe it could
be nice to be able to access Solr from one of those. VMS Pascal
is actually a very nice language, so I picked that. And I could
reuse some stuff I had on the shelf.

pSolr (Pascal)-|->phttp (Pascal)->vms_http (C)->vms_socket (C)->sockets
|->pJSON (Pascal)->cJSON (C, not written by me)

Demo:

$ type load.pas
[inherit('common','pSolr')]
program load(input,output);

var
solr : solr_ctxptr;

begin
solr := psolr_setup('arnepc5', 8888, 'chessopening');
psolr_delete(solr, '*:*');
psolr_insert(solr, 1, 'names', 'Spanish defense, Ruy Lopez',
'moves', '1. e4, e5, 2. Nf3, Nc6, 3. Bb5,');
psolr_insert(solr, 2, 'names', 'French defense', 'moves', '1. e4,
e6, 2. d4, d5,');
psolr_insert(solr, 3, 'names', 'Sicilian defense', 'moves', '1. e4,
c5,');
psolr_insert(solr, 4, 'names', 'Queens gambit', 'moves', '1. d4, d5,
2. c4,');
psolr_insert(solr, 5, 'names', 'Dutch defense', 'moves', 'd4, f5,');
psolr_insert(solr, 6, 'names', 'Reti opening', 'moves', 'Nf3, d5, 2.
c4,');
end.
$ pas load
$ link load + psolr/libr
$ run load
$ type search.pas
[inherit('common','pSolr')]
program search(input,output);

procedure dump(solr : solr_ctxptr; query : pstr);

var
res : solr_query_res;
i : integer;

begin
writeln('search for : ' + query);
res := psolr_query_df(solr, query, 'alltext');
for i := 1 to psolr_hits(res) do begin
writeln(' ', psolr_get_field(res, i-1, 'names'), ' - ',
psolr_get_field(res, i-1, 'moves'));
end;
end;

var
solr : solr_ctxptr;

begin
solr := psolr_setup('arnepc5', 8888, 'chessopening');
(* all *)
dump(solr, '*:*');
(* one *)
dump(solr, 'names:defense');
dump(solr, 'moves:d4');
(* dual *)
dump(solr, 'alltext:defense');
dump(solr, 'alltext:d4');
dump(solr, 'defense'); (* default field *)
dump(solr, 'd4'); (* default field *)
(* boolean *)
dump(solr, 'names:defense moves:d4'); (* implicit or *)
dump(solr, 'names:defense AND moves:d4'); (* and *)
dump(solr, 'names:defense NOT moves:d4'); (* not *)
dump(solr, 'defense d4'); (* default field + implicit or *)
dump(solr, 'defense AND d4'); (* default field + and *)
dump(solr, 'defense NOT d4'); (* default field + not *)
(* wildcard *)
dump(solr, 'names:def*');
dump(solr, 'moves:N*');
end.
$ pas search
$ link search + psolr/libr
$ run search
search for : *:*
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
French defense - 1. e4, e6, 2. d4, d5,
Sicilian defense - 1. e4, c5,
Queens gambit - 1. d4, d5, 2. c4,
Dutch defense - d4, f5,
Reti opening - Nf3, d5, 2. c4,
search for : names:defense
French defense - 1. e4, e6, 2. d4, d5,
Sicilian defense - 1. e4, c5,
Dutch defense - d4, f5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : moves:d4
Dutch defense - d4, f5,
Queens gambit - 1. d4, d5, 2. c4,
French defense - 1. e4, e6, 2. d4, d5,
search for : alltext:defense
Dutch defense - d4, f5,
Sicilian defense - 1. e4, c5,
French defense - 1. e4, e6, 2. d4, d5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : alltext:d4
Dutch defense - d4, f5,
Queens gambit - 1. d4, d5, 2. c4,
French defense - 1. e4, e6, 2. d4, d5,
search for : defense
Dutch defense - d4, f5,
Sicilian defense - 1. e4, c5,
French defense - 1. e4, e6, 2. d4, d5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : d4
Dutch defense - d4, f5,
Queens gambit - 1. d4, d5, 2. c4,
French defense - 1. e4, e6, 2. d4, d5,
search for : names:defense moves:d4
Dutch defense - d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
Queens gambit - 1. d4, d5, 2. c4,
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : names:defense AND moves:d4
Dutch defense - d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
search for : names:defense NOT moves:d4
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : defense d4
Dutch defense - d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
Queens gambit - 1. d4, d5, 2. c4,
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : defense AND d4
Dutch defense - d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
search for : defense NOT d4
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : names:def*
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
French defense - 1. e4, e6, 2. d4, d5,
Sicilian defense - 1. e4, c5,
Dutch defense - d4, f5,
search for : moves:N*
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
Reti opening - Nf3, d5, 2. c4,

Very far from a complete API - only the most basic stuff.

And there are restrictions including 32 KB limit on strings
(VMS Pascal varying of char).

But maybe still interesting.

If anyone is interested then everything is available here:
https://www.vajhoej.dk/arne/opensource/vms/vmspsolr-src-v0_1.zip

Arne
Arne Vajhøj
2024-12-10 02:04:40 UTC
Reply
Permalink
Post by Arne Vajhøj
I have been looking a bit at Solr recently. For those that don't
know Solr, then it is a text search engine - or more accurate it
is a web frontend for the Lucene text search engine. Both
Solr and Lucene are Apache projects (open source).
Solr is basically exposing a web API, so anything that can do
HTTP POST can use Solr. But clients encapsulating the HTTP
stuff does exist for many languages. On VMS then both JVM languages
and Python should be able to use a standard client.
But there are also the traditional languages. Maybe it could
be nice to be able to access Solr from one of those.  VMS Pascal
is actually a very nice language, so I picked that. And I could
reuse some stuff I had on the shelf.
pSolr (Pascal)-|->phttp (Pascal)->vms_http (C)->vms_socket (C)->sockets
               |->pJSON (Pascal)->cJSON (C, not written by me)
To do a little stress test I tried stuffing the content of
SYS$HELP:HELPLIB.HLB into Solr (two fields: path with the
help path and helptext with the first 32 KB of the text).

And then a little search program that output help commands
that can be copy pasted.

Examples:

$ mcr []hhint fread
help CRTL fread
help CRTL fread Description
help CRTL Version-Dependency_Tables All_OpenVMS_Versions
help CRTL pipe Description
$ mcr []hhint fread NOT fwrite
help CRTL fread
help CRTL fread Description
$ mcr []hhint fread OR fwrite
help CRTL fread
help CRTL fwrite
help CRTL Feature_Logical_Names DECC$STDIO_CTX_EOL
help CRTL fwrite Description
help CRTL fread Description
help CRTL Feature_Logical_Names DECC$WRITE_SHORT_RECORDS
help CRTL Version-Dependency_Tables All_OpenVMS_Versions
help CRTL pipe Description

Arne
Arne Vajhøj
2024-12-25 18:39:08 UTC
Reply
Permalink
Post by Arne Vajhøj
I have been looking a bit at Solr recently. For those that don't
know Solr, then it is a text search engine - or more accurate it
is a web frontend for the Lucene text search engine. Both
Solr and Lucene are Apache projects (open source).
Solr is basically exposing a web API, so anything that can do
HTTP POST can use Solr. But clients encapsulating the HTTP
stuff does exist for many languages. On VMS then both JVM languages
and Python should be able to use a standard client.
Python:

$ type load.py
import solr

client = solr.SolrConnection('http://arnepc5:8888/solr/chessopening')
client.delete_query('*:*')
client.add(id=1, names='Spanish defense, Ruy Lopez', moves='1. e4, e5,
2. Nf3, Nc6, 3. Bb5,')
client.add(id=2, names='French defense', moves='1. e4, e6, 2. d4, d5,')
client.add(id=3, names='Sicilian defense', moves='1. e4, c5,')
client.add(id=4, names='Queens gambit', moves='1. d4, d5, 2. c4,')
client.add(id=5, names='Dutch defense', moves='1. d4, f5,')
client.add(id=6, names='Reti opening', moves='1. Nf3, d5, 2. c4,')
client.commit()
$ python load.py
<add><doc><field name="id">1</field><field name="names">Spanish defense,
Ruy Lopez</field><field name="moves">1. e4, e5, 2. Nf3, Nc6
, 3. Bb5,</field></doc></add>
<add><doc><field name="id">2</field><field name="names">French
defense</field><field name="moves">1. e4, e6, 2. d4, d5,</field></doc
Post by Arne Vajhøj
</add>
<add><doc><field name="id">3</field><field name="names">Sicilian
defense</field><field name="moves">1. e4, c5,</field></doc></add>
<add><doc><field name="id">4</field><field name="names">Queens
gambit</field><field name="moves">1. d4, d5, 2. c4,</field></doc></ad
d>
<add><doc><field name="id">5</field><field name="names">Dutch
defense</field><field name="moves">1. d4, f5,</field></doc></add>
<add><doc><field name="id">6</field><field name="names">Reti
opening</field><field name="moves">1. Nf3, d5, 2. c4,</field></doc></ad
d>
$ type search.py
import solr

def dump(client, searchterm):
print('search for : %s' % (searchterm))
res = client.query(searchterm, df='alltext').results
for doc in res:
print(' %s - %s' % (doc['names'], doc['moves']))

client = solr.SolrConnection('http://arnepc5:8888/solr/chessopening')
# all
dump(client, '*:*')
# one
dump(client, 'names:defense')
dump(client, 'moves:d4')
# dual
dump(client, 'alltext:defense')
dump(client, 'alltext:d4')
dump(client, 'defense') # default field
dump(client, 'd4') # default field
# boolean
dump(client, 'names:defense moves:d4') # implicit or
dump(client, 'names:defense AND moves:d4') # and
dump(client, 'names:defense NOT moves:d4') # not
dump(client, 'defense d4') # default field + implicit or
dump(client, 'defense AND d4') # default field + and
dump(client, 'defense NOT d4') # default field + not
# wildcard
dump(client, 'names:def*')
dump(client, 'moves:N*')
$ python search.py
search for : *:*
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
French defense - 1. e4, e6, 2. d4, d5,
Sicilian defense - 1. e4, c5,
Queens gambit - 1. d4, d5, 2. c4,
Dutch defense - 1. d4, f5,
Reti opening - 1. Nf3, d5, 2. c4,
search for : names:defense
French defense - 1. e4, e6, 2. d4, d5,
Sicilian defense - 1. e4, c5,
Dutch defense - 1. d4, f5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : moves:d4
Dutch defense - 1. d4, f5,
Queens gambit - 1. d4, d5, 2. c4,
French defense - 1. e4, e6, 2. d4, d5,
search for : alltext:defense
Sicilian defense - 1. e4, c5,
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : alltext:d4
Dutch defense - 1. d4, f5,
Queens gambit - 1. d4, d5, 2. c4,
French defense - 1. e4, e6, 2. d4, d5,
search for : defense
Sicilian defense - 1. e4, c5,
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : d4
Dutch defense - 1. d4, f5,
Queens gambit - 1. d4, d5, 2. c4,
French defense - 1. e4, e6, 2. d4, d5,
search for : names:defense moves:d4
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
Queens gambit - 1. d4, d5, 2. c4,
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : names:defense AND moves:d4
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
search for : names:defense NOT moves:d4
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : defense d4
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
Queens gambit - 1. d4, d5, 2. c4,
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : defense AND d4
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
search for : defense NOT d4
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : names:def*
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
French defense - 1. e4, e6, 2. d4, d5,
Sicilian defense - 1. e4, c5,
Dutch defense - 1. d4, f5,
search for : moves:N*
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
Reti opening - 1. Nf3, d5, 2. c4,

Arne
Simon Clubley
2025-01-02 13:23:18 UTC
Reply
Permalink
On 2024-12-25, Arne Vajhøj <***@vajhoej.dk> wrote:
^^^^^^^^^^
Post by Arne Vajhøj
Post by Arne Vajhøj
I have been looking a bit at Solr recently. For those that don't
know Solr, then it is a text search engine - or more accurate it
is a web frontend for the Lucene text search engine. Both
Solr and Lucene are Apache projects (open source).
Solr is basically exposing a web API, so anything that can do
HTTP POST can use Solr. But clients encapsulating the HTTP
stuff does exist for many languages. On VMS then both JVM languages
and Python should be able to use a standard client.
$ type load.py
import solr
[snip]

$ set response/mode=very_good_natured

Generally, people do Christmas stuff on Christmas Day. :-) :-)

Simon.
--
Simon Clubley, ***@remove_me.eisner.decus.org-Earth.UFP
Walking destinations on a map are further away than they appear.
Arne Vajhøj
2024-12-25 18:42:26 UTC
Reply
Permalink
Post by Arne Vajhøj
I have been looking a bit at Solr recently. For those that don't
know Solr, then it is a text search engine - or more accurate it
is a web frontend for the Lucene text search engine. Both
Solr and Lucene are Apache projects (open source).
Solr is basically exposing a web API, so anything that can do
HTTP POST can use Solr. But clients encapsulating the HTTP
stuff does exist for many languages. On VMS then both JVM languages
and Python should be able to use a standard client.
Groovy:

$ groovy_cp = "solrj/solr-solrj-8.11.4.jar"
$ type Load.groovy
import org.apache.solr.client.solrj.*
import org.apache.solr.client.solrj.impl.*
import org.apache.solr.common.*

def create(id, names, moves) {
res = new SolrInputDocument()
res.addField("id", id)
res.addField("names", names)
res.addField("moves", moves)
return res
}

client = new HttpSolrClient.Builder("http://arnepc5:8888/solr").build()
client.deleteByQuery("chessopening", "*:*")
client.add("chessopening", create(1, "Spanish defense, Ruy Lopez", "1.
e4, e5, 2. Nf3, Nc6, 3. Bb5,"))
client.add("chessopening", create(2, "French defense", "1. e4, e6, 2.
d4, d5,"))
client.add("chessopening", create(3, "Sicilian defense", "1. e4, c5,"))
client.add("chessopening", create(4, "Queens gambit", "1. d4, d5, 2. c4,"))
client.add("chessopening", create(5, "Dutch defense", "1. d4, f5,"))
client.add("chessopening", create(6, "Reti opening", "1. Nf3, d5, 2. c4,"))
client.commit("chessopening")
client.close()
$ groovyc """Load.groovy"""
$ java -cp .:solrj/*:/disk0/net/groovy/groovy-4.0.12/lib/* Load
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for
further details.
$ type Search.groovy
import org.apache.solr.client.solrj.*
import org.apache.solr.client.solrj.impl.*
import org.apache.solr.common.*

def dump(client, searchterm) {
printf("search for : %s\n", searchterm)
query = new SolrQuery()
query.setParam("df", "alltext")
query.setQuery(searchterm)
query.addField("names")
query.addField("moves")
res = client.query("chessopening", query).getResults()
for(doc in res) {
names = doc.getFirstValue("names")
moves = doc.getFirstValue("moves")
printf(" %s - %s\n", names, moves)
}
}

client = new HttpSolrClient.Builder("http://arnepc5:8888/solr").build()
// all
dump(client, "*:*")
// one
dump(client, "names:defense")
dump(client, "moves:d4")
// dual
dump(client, "alltext:defense")
dump(client, "alltext:d4")
dump(client, "defense") // default field
dump(client, "d4") // default field
// boolean
dump(client, "names:defense moves:d4") // implicit or
dump(client, "names:defense AND moves:d4") // and
dump(client, "names:defense NOT moves:d4") // not
dump(client, "defense d4") // default field + implicit or
dump(client, "defense AND d4") // default field + and
dump(client, "defense NOT d4") // default field + not
// wildcard
dump(client, "names:def*")
dump(client, "moves:N*")
client.close()
$ groovyc """Search.groovy"""
$ java -cp .:solrj/*:/disk0/net/groovy/groovy-4.0.12/lib/* Search
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for
further details.
search for : *:*
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
French defense - 1. e4, e6, 2. d4, d5,
Sicilian defense - 1. e4, c5,
Queens gambit - 1. d4, d5, 2. c4,
Dutch defense - 1. d4, f5,
Reti opening - 1. Nf3, d5, 2. c4,
search for : names:defense
French defense - 1. e4, e6, 2. d4, d5,
Sicilian defense - 1. e4, c5,
Dutch defense - 1. d4, f5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : moves:d4
Dutch defense - 1. d4, f5,
Queens gambit - 1. d4, d5, 2. c4,
French defense - 1. e4, e6, 2. d4, d5,
search for : alltext:defense
Sicilian defense - 1. e4, c5,
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : alltext:d4
Dutch defense - 1. d4, f5,
Queens gambit - 1. d4, d5, 2. c4,
French defense - 1. e4, e6, 2. d4, d5,
search for : defense
Sicilian defense - 1. e4, c5,
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : d4
Dutch defense - 1. d4, f5,
Queens gambit - 1. d4, d5, 2. c4,
French defense - 1. e4, e6, 2. d4, d5,
search for : names:defense moves:d4
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
Queens gambit - 1. d4, d5, 2. c4,
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : names:defense AND moves:d4
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
search for : names:defense NOT moves:d4
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : defense d4
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
Queens gambit - 1. d4, d5, 2. c4,
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : defense AND d4
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
search for : defense NOT d4
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : names:def*
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
French defense - 1. e4, e6, 2. d4, d5,
Sicilian defense - 1. e4, c5,
Dutch defense - 1. d4, f5,
search for : moves:N*
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
Reti opening - 1. Nf3, d5, 2. c4,

Arne
Lawrence D'Oliveiro
2024-12-25 20:41:52 UTC
Reply
Permalink
Post by Arne Vajhøj
import org.apache.solr.client.solrj.*
import org.apache.solr.client.solrj.impl.*
import org.apache.solr.common.*
Stopped reading at wildcard imports.

Avoid.
Arne Vajhøj
2024-12-25 18:43:42 UTC
Reply
Permalink
Post by Arne Vajhøj
I have been looking a bit at Solr recently. For those that don't
know Solr, then it is a text search engine - or more accurate it
is a web frontend for the Lucene text search engine. Both
Solr and Lucene are Apache projects (open source).
Solr is basically exposing a web API, so anything that can do
HTTP POST can use Solr. But clients encapsulating the HTTP
stuff does exist for many languages. On VMS then both JVM languages
and Python should be able to use a standard client.
Java:

$ type Load.java
import java.io.IOException;

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.common.SolrInputDocument;

public class Load {
private static SolrInputDocument create(int id, String names,
String moves) {
SolrInputDocument res = new SolrInputDocument();
res.addField("id", id);
res.addField("names", names);
res.addField("moves", moves);
return res;
}
public static void main(String[] args) throws IOException,
SolrServerException {
HttpSolrClient client = new
HttpSolrClient.Builder("http://arnepc5:8888/solr").build();
client.deleteByQuery("chessopening", "*:*");
client.add("chessopening", create(1, "Spanish defense, Ruy
Lopez", "1. e4, e5, 2. Nf3, Nc6, 3. Bb5,"));
client.add("chessopening", create(2, "French defense", "1. e4,
e6, 2. d4, d5,"));
client.add("chessopening", create(3, "Sicilian defense", "1.
e4, c5,"));
client.add("chessopening", create(4, "Queens gambit", "1. d4,
d5, 2. c4,"));
client.add("chessopening", create(5, "Dutch defense", "1. d4,
f5,"));
client.add("chessopening", create(6, "Reti opening", "1. Nf3,
d5, 2. c4,"));
client.commit("chessopening");
client.close();
}
}
$ javac -cp solrj/* Load.java
$ java -cp .:solrj/* Load
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for
further details.
$ type Search.java
import java.io.IOException;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;

public class Search {
private static void dump(HttpSolrClient client, String searchterm)
throws SolrServerException, IOException {
System.out.printf("search for : %s\n", searchterm);
SolrQuery query = new SolrQuery();
query.setParam("df", "alltext");
query.setQuery(searchterm);
query.addField("names");
query.addField("moves");
SolrDocumentList res = client.query("chessopening",
query).getResults();
for(SolrDocument doc : res) {
String names = (String)doc.getFirstValue("names");
String moves = (String)doc.getFirstValue("moves");
System.out.printf(" %s - %s\n", names, moves);
}
}
public static void main(String[] args) throws IOException,
SolrServerException {
HttpSolrClient client = new
HttpSolrClient.Builder("http://arnepc5:8888/solr").build();
// all
dump(client, "*:*");
// one
dump(client, "names:defense");
dump(client, "moves:d4");
// dual
dump(client, "alltext:defense");
dump(client, "alltext:d4");
dump(client, "defense"); // default field
dump(client, "d4"); // default field
// boolean
dump(client, "names:defense moves:d4"); // implicit or
dump(client, "names:defense AND moves:d4"); // and
dump(client, "names:defense NOT moves:d4"); // not
dump(client, "defense d4"); // default field + implicit or
dump(client, "defense AND d4"); // default field + and
dump(client, "defense NOT d4"); // default field + not
// wildcard
dump(client, "names:def*");
dump(client, "moves:N*");
client.close();
}
}
$ javac -cp solrj/* Search.java
$ java -cp .:solrj/* Search
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for
further details.
search for : *:*
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
French defense - 1. e4, e6, 2. d4, d5,
Sicilian defense - 1. e4, c5,
Queens gambit - 1. d4, d5, 2. c4,
Dutch defense - 1. d4, f5,
Reti opening - 1. Nf3, d5, 2. c4,
search for : names:defense
French defense - 1. e4, e6, 2. d4, d5,
Sicilian defense - 1. e4, c5,
Dutch defense - 1. d4, f5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : moves:d4
Dutch defense - 1. d4, f5,
Queens gambit - 1. d4, d5, 2. c4,
French defense - 1. e4, e6, 2. d4, d5,
search for : alltext:defense
Sicilian defense - 1. e4, c5,
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : alltext:d4
Dutch defense - 1. d4, f5,
Queens gambit - 1. d4, d5, 2. c4,
French defense - 1. e4, e6, 2. d4, d5,
search for : defense
Sicilian defense - 1. e4, c5,
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : d4
Dutch defense - 1. d4, f5,
Queens gambit - 1. d4, d5, 2. c4,
French defense - 1. e4, e6, 2. d4, d5,
search for : names:defense moves:d4
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
Queens gambit - 1. d4, d5, 2. c4,
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : names:defense AND moves:d4
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
search for : names:defense NOT moves:d4
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : defense d4
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
Queens gambit - 1. d4, d5, 2. c4,
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : defense AND d4
Dutch defense - 1. d4, f5,
French defense - 1. e4, e6, 2. d4, d5,
search for : defense NOT d4
Sicilian defense - 1. e4, c5,
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
search for : names:def*
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
French defense - 1. e4, e6, 2. d4, d5,
Sicilian defense - 1. e4, c5,
Dutch defense - 1. d4, f5,
search for : moves:N*
Spanish defense, Ruy Lopez - 1. e4, e5, 2. Nf3, Nc6, 3. Bb5,
Reti opening - 1. Nf3, d5, 2. c4,

Arne
Arne Vajhøj
2024-12-27 19:43:39 UTC
Reply
Permalink
Post by Arne Vajhøj
I have been looking a bit at Solr recently. For those that don't
know Solr, then it is a text search engine - or more accurate it
is a web frontend for the Lucene text search engine. Both
Solr and Lucene are Apache projects (open source).
Solr is basically exposing a web API, so anything that can do
HTTP POST can use Solr. But clients encapsulating the HTTP
stuff does exist for many languages. On VMS then both JVM languages
and Python should be able to use a standard client.
But there are also the traditional languages. Maybe it could
be nice to be able to access Solr from one of those.  VMS Pascal
is actually a very nice language, so I picked that. And I could
reuse some stuff I had on the shelf.
Very far from a complete API - only the most basic stuff.
And there are restrictions including 32 KB limit on strings
(VMS Pascal varying of char).
But maybe still interesting.
  https://www.vajhoej.dk/arne/opensource/vms/vmspsolr-src-v0_1.zip
https://www.vajhoej.dk/arne/opensource/vms/vmspsolr-src-v0_3.zip

has:
* the help stuff
* use GET instead of POST for query making it work with
older Solr (the version I got get running in Tomcat on VMS)

Arne
Loading...