среда, 27 декабря 2017 г.

Stemming Apache Lucene example Russian language

Example of Stemming Apache Lucene - Russian language:


String querystr = "Проводнику большие";

Analyzer analyzer = new RussianAnalyzer(Version.LUCENE_40);

Directory index = new RAMDirectory();

IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40, analyzer);

IndexWriter w = new IndexWriter(index, config);
addDoc(w, "Проводник большой", "193398817");
addDoc(w, "Проводнику большому", "55320055Z");
addDoc(w, "Проводные большие", "55063554A");
addDoc(w, "Большие проводники", "9900333X");
w.close();

Query q = new QueryParser(Version.LUCENE_40, "title", analyzer).parse(querystr);

int hitsPerPage = 10;
IndexReader reader = DirectoryReader.open(index);
IndexSearcher searcher = new IndexSearcher(reader);
TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true);
searcher.search(q, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;

System.out.println("Found " + hits.length + " hits.");
for (int i = 0; i < hits.length; ++i) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
System.out.println((i + 1) + ". " + d.get("isbn") + "\t" + d.get("title"));
}

reader.close();

вторник, 12 декабря 2017 г.

How to call SAP BPM OData service api from jQuery ajax

How to call SAP BPM OData service api from jQuery ajax.

Call with "GET" method:
If you want to call BPM OData service via http "GET" method, then you just call it via jQuery $.ajax.

Call with "POST" method:
If you want to call BPM OData service via http "POST" method, then first you have to call some BPM OData service with "GET" method with http header 'x-csrf-token' with value 'Fetch' to get token. Then you have to call BPM OData service with "POST" method and you have to set 'x-csrf-token' header which you recieved in previous step.

Example:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<div class="MyTest">Hello</div>
<div class="result1">result1</div>
<div class="result2">result2</div>

<script type="text/javascript">

$.ajax({
    url: "http://<server>:<port>/bpmodata/processes.svc/ProcessCollection('<bpm process id>')?$format=json",
    headers: {     
        'x-csrf-token':'Fetch',     
    },
    method: 'GET',
    success: function(data, textStatus, request){
var myToken = request.getResponseHeader('x-csrf-token');                
        $(".result1").html(myToken);

        $.ajax({
            url: "http://<server>:<port>/bpmodata/processes.svc/Cancel?InstanceId='<bpm process id>'&$format=json",
            headers: {     
                'x-csrf-token': myToken,     
            },
            method: 'POST',
            success: function(data, textStatus, request){                
                $(".result2").html('completed');
           },
           error: function (request, textStatus, errorThrown) {
                alert('Error');
           } 
        });
     
   },
   error: function (request, textStatus, errorThrown) {
        alert('Error' + request.getResponseHeader('x-csrf-token'));
   }

 
  });

</script>

</body>
</html>