[Lazarus] getlazarus.org search request

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list
getlazarus.org has a really excellent search feature but I’d like to make a request (I think the owner posts here which is why I’m asking). Could an additional API be added so that we could use 3rd party editors with it?

In particular what I’d like to do is being able to send a HTTP request with the currently selected word and have it pull up the best result. I understand this doesn’t work with words like “Create” but it works well for types names. For example if:

http://docs.getlazarus.org/search.php?TStringList

Regards,
        Ryan Joseph

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list
Ryan, that is a good idea and I can absolutely add a search page that pulls a string from RESTful query string and returns a friendly hyperlinked summary of the most useful results. Also, I don't know if you know this, but you can edit Lazarus settings to open up https://docs.getlazarus.org to the appropriate page when you press F1 on any identifier in the code editor.

Tools -> Options -> Help -> Help Options
  set StartPage / BaseURL = https://docs.getlazarus.org/
  set RTLUnits / BaseURL = https://docs.getlazarus.org/rtl/
  set FCLUnits / BaseURL = https://docs.getlazarus.org/fcl/
  set LCLUnits / BaseURL = https://docs.getlazarus.org/lcl/

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
Ryan,

I was going to modify my project to allow for RESTful queries, when I realized it already does this. The url and format are as follows:


Alternate request for xml format:


Currently there is no custom formatting applied as this is meant to be an AJAX request to create populate suggestions. As this is an API like RESTful function is this good enough for you or do want a "pretty" result format?

Here are the templates, which I could easy swap out based on another request parameter:

Page uses this template as an html fragment:

<div id="searchResults">{SearchItems}</div>

Results collection uses this template:

<a class="searchResult" href="{Source}" target="main" onclick="searchSelect('{Path}')">
<span class="resultPath">{Bolden}</span>
<span class="resultKind">{Kind}</span>
<span class="resultDescription">{Description}</span>
</a>

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list


> On Aug 11, 2019, at 1:51 PM, Anthony Walter via lazarus <[hidden email]> wrote:
>
> Ryan,
>
> I was going to modify my project to allow for RESTful queries, when I realized it already does this. The url and format are as follows:
>
> https://docs.getlazarus.org/?method=codesearch&phrase=TStringList

Excellent, thanks for your foresight :). Could it be adapted so that there’s an option to show the page of the top result? For example in the query above a list of links is displayed but it would be better if the top result (https://docs.getlazarus.org/#rtl+classes+tstringlist) was loaded automatically. The fact that “TStringList” shows the correct page as the best result means this will work for 99% of the use cases I have in mind.

Regards,
        Ryan Joseph

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list


> On Aug 11, 2019, at 1:51 PM, Anthony Walter via lazarus <[hidden email]> wrote:
>
> Currently there is no custom formatting applied as this is meant to be an AJAX request to create populate suggestions. As this is an API like RESTful function is this good enough for you or do want a "pretty" result format?
>

Making a pretty formatted option would be nice also actually. It’s already basically there but a few line breaks would make it more useable. :)

Regards,
        Ryan Joseph

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
Ryan,

My sites are built on my custom web class library that optionally uses templates to generate content. Templates are simple fill in the blank page type text files which use reflection to pull properties of a objects into the template.

Here is how a template is formatted:

<html>
<head>
<title>Search Results: {Phrase}</title>
<link href="/styles/your.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>
{SearchItems}
</body>
</html>

And a template file for the search item: 

<a class="searchResult" href="{Source}">
<span class="resultPath">{Bolden}</span>
<span class="resultKind">{Kind}</span>
<span class="resultDescription">{Description}</span>

If you want something specific with regards to layout, just send me a custom template and possibly a css file to make it look however you want.

Since I have written this web library myself, its very easy to modify and extend. I might add the ability for anyone to send their own templates and browse or select from templates directly on every page, but that extension is not likely to happen in the next few days.

If anyone is interested let me know and I'd produce a short instructional video on how the my web library makes developing web pages easy. The only hard part is writing html and css, which for plain stuff isn't hard at all really. But html and css are design work, so you get out of html and css work is whatever kind of design, taste, and effort you put into it.

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list


On Sun, 11 Aug 2019, Anthony Walter via lazarus wrote:

> Ryan,
>
> My sites are built on my custom web class library that optionally uses
> templates to generate content. Templates are simple fill in the blank page
> type text files which use reflection to pull properties of a objects into
> the template.

I'm a bit surprised you still write custom things for this.
All this is available by default in the FPC web classes.
Templating is as old as the web, after all.

Michael.
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list
Michael,

Here is an example of how easy it is.

    public class CodeSearch : TemplateHandler
    {
        private static readonly string searchSql = "search.sql".LoadResourceText();

        protected override void Run(Templates templates, 
StringBuilder output)
        {
            SearchItems = DataCommand
                .Prepare(searchSql)
                .Add("@phrase", 
Read("phrase"))
                .Compose();
            templates[Read("format") + "SearchItem"].FormatObject(this, output);
        }

        public IEnumerable<object> SearchItems { get; set; }
    }


1) The library automatically finds the CodeSearch class without any code to write
2) It runs the template handler automatically
3) In run we execute some SQL to search for a phrase and compose the results as a collection of anonymous objects
4) The we select the template we want and format the CodeSearch object and its available properties, in this case our search result "SearchItems".

The FormatObject method is a template engine that uses reflection to lookup properties with mustache braces. It has the ability to query subproperties and use all available format specifiers. Collection properties (IEnumerable<T>) are expanded by a detail template that can read through reflection the properties of the anonymous objects in the collection by name and template them as well.

Here are some template examples. Note you can access sub properties using object.suprop.susubprop syntax as well as custom formatting in the template (i.e. Price:C2 or Page.Modified:yyyyy-mm-dd).

<title>{Title}</title> or <title>{Page.Title}</title> // Welcome to our website
<div>Price is {Amount:C2}</div> // Price is $15.75
<div>Page modified on {Page.Modified:yyyyy-mm-dd}</div> // Page modified on 2019-07-10
<div>{SeachItems}</div> // Expands our template



--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list


Ah, but this is C# ?

I don't think you need more code in FPC to do the same.
But if there are proposals to reduce the amount of code in FPC even more, I'm open for suggestions.

Michael.

On Mon, 12 Aug 2019, Anthony Walter via lazarus wrote:

> Michael,
>
> Here is an example of how easy it is.
>
>    public class CodeSearch : TemplateHandler
>    {
>        private static readonly string searchSql =
> "search.sql".LoadResourceText();
>
>        protected override void Run(Templates templates, StringBuilder
> output)
>        {
>            SearchItems = DataCommand
>                .Prepare(searchSql)
>                .Add("@phrase", Read("phrase"))
>                .Compose();
>            templates[Read("format") + "SearchItem"].FormatObject(this,
> output);
>        }
>
>        public IEnumerable<object> SearchItems { get; set; }
>    }
>
> So given the url,
> https://docs.getlazarus.org/?method=codesearch&format=xml&phrase=TStringList in
> steps:
>
> 1) The library automatically finds the CodeSearch class without any code to
> write
> 2) It runs the template handler automatically
> 3) In run we execute some SQL to search for a phrase and compose the
> results as a collection of anonymous objects
> 4) The we select the template we want and format the CodeSearch object and
> its available properties, in this case our search result "SearchItems".
>
> The FormatObject method is a template engine that uses reflection to lookup
> properties with mustache braces. It has the ability to query subproperties
> and use all available format specifiers. Collection properties (IEnumerable
> <T>) are expanded by a detail template that can read through reflection the
> properties of the anonymous objects in the collection by name and template
> them as well.
>
> Here are some template examples. Note you can access sub properties using
> object.suprop.susubprop syntax as well as custom formatting in the template
> (i.e. Price:C2 or Page.Modified:yyyyy-mm-dd).
>
> <title>{Title}</title> or <title>{Page.Title}</title> // Welcome to our
> website
> <div>Price is {Amount:C2}</div> // Price is $15.75
> <div>Page modified on {Page.Modified:yyyyy-mm-dd}</div> // Page modified on
> 2019-07-10
> <div>{SeachItems}</div> // Expands our template
>
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list
Yes, in C#. Personally I find ASP.NET or Core easier to use than a CGI executable. Also the ability to dynamically compose anonymous objects, write linq expressions, and use reflection can be quite powerful. 

The object formatting system is C#, where everything is an object and custom formatters can be easily added, allow for the same formatting strings in both compiled code and external template files.

As is right now, the only time consuming or potentially difficult part is writing html / css. As I mentioned html / css can be a time sink depending on how much design, taste, and effort you want to put into the actual page spit out in the end.

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list


On Mon, 12 Aug 2019, Anthony Walter via lazarus wrote:

> Yes, in C#. Personally I find ASP.NET or Core easier to use than a CGI
> executable.

I assumed you wrote your classes for FPC.

If you use the Microsoft stack, then my remarks are of no importance.

Michael.
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list
I use FPC for a lot of web stuff, but generally not for servers. In this project I am using an FPC program to create the database and download updates using my TClientSocket class.

For long running stuff, which I may typically host on an Amazon cloud server with Linux, I'll generally either use something from a package (apt or docker) or write a custom service in C# hosted in Kestrel or Apache.

Don't worry though, I spend most of my time writing desktop apps, and for that nothing beats FPC + Lazarus ;)

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list


On Mon, 12 Aug 2019, Anthony Walter via lazarus wrote:

> I use FPC for a lot of web stuff, but generally not for servers. In this
> project I am using an FPC program to create the database and download
> updates using my TClientSocket class.
>
> For long running stuff, which I may typically host on an Amazon cloud
> server with Linux, I'll generally either use something from a package (apt
> or docker) or write a custom service in C# hosted in Kestrel or Apache.
>
> Don't worry though, I spend most of my time writing desktop apps, and for
> that nothing beats FPC + Lazarus ;)

Well, I use FPC mostly for web, so almost exactly the opposite of what you
do.

If we put our experiences together, it leads me to the conclusion that
FPC+Lazarus effectively covers all scenarios :-)

That said, there is of course always room for improvement,
so as I said before I'm open for suggestions to make things easier.

Michael

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On 12/08/2019 9:33 am, Anthony Walter via lazarus wrote:
>         public IEnumerable<object> SearchItems { get; set; }


I don't know C# at all, but am curious regarding this. What does that
"get" and "set" do?  It that a shorthand syntax for implementing getters
and setters of a field variable?


Regards,
  Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list
In C# to define a property you write:

visibility typename propname { [visibility] get; [visibility] set; } 
-or-
public int Age { get; set; }

This means you have a read write property that does nothing special. You could also write ...

private int age;
public int Age { get { return age; } set { if (value > -1) age = value; } }

To use private a backing with code invoked to set or get. And finally you can also write:

public int Age { get; private set; }
-or-
public int Age { get; private set; }
-or-
public int Age { get; protected set; }

To limit access to either a setter or getter of a property.







--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On Mon, Aug 12, 2019 at 6:36 AM Michael Van Canneyt via lazarus
<[hidden email]> wrote:
>
> [...] FPC+Lazarus effectively covers all scenarios :-)

No doubt about that for sure.

Marcos Douglas
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list


> On Aug 11, 2019, at 9:05 PM, Anthony Walter via lazarus <[hidden email]> wrote:
>
> Ryan,
>
> My sites are built on my custom web class library that optionally uses templates to generate content. Templates are simple fill in the blank page type text files which use reflection to pull properties of a objects into the template.
>

Thanks. I had a better idea. Would it be possible to make a split view where the search results are in a side bar and the main view shows the first result automatically? 99% of the time when I search for TStringList I want the class definition page (and clicking to get to it would be an extra step even) but having a side bar with additional results would make it complete.

Regards,
        Ryan Joseph

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] getlazarus.org search request

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list

Op 2019-08-12 om 11:13 schreef Anthony Walter via lazarus:
> Yes, in C#. Personally I find ASP.NET <http://ASP.NET> or Core easier
> to use than a CGI executable

Well, something like ISAPI dlls are inbetween those for a long,long time.


--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus